| 1 | /* praat.cpp |
| 2 | * |
| 3 | * Copyright (C) 1992-2026 Paul Boersma |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 3 of the License, or (at |
| 8 | * your option) any later version. |
| 9 | * |
| 10 | * This code is distributed in the hope that it will be useful, but |
| 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 13 | * See the GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this work. If not, see <http://www.gnu.org/licenses/>. |
| 17 | */ |
| 18 | |
| 19 | #include "melder.h"cxx . . $ `<file>/melder/melder.h`/ |
| 20 | #include <stdarg.h> |
| 21 | #if defined (UNIXcxx . . $ `<built-in>:479:9`!) || defined (macintosh) |
| 22 | #include <sys/types.h> |
| 23 | #include <sys/stat.h> |
| 24 | #include <signal.h> |
| 25 | #endif |
| 26 | #include <locale.h> |
| 27 | #if defined (UNIXcxx . . $ `<built-in>:479:9`!) |
| 28 | #include <unistd.h> |
| 29 | #endif |
| 30 | #if defined (_WIN32) |
| 31 | #include <windows.h> |
| 32 | #include <fcntl.h> |
| 33 | #include <io.h> |
| 34 | #include <process.h> // getpid |
| 35 | #endif |
| 36 | |
| 37 | #include "praatP.h"cxx . . $ `<file>/sys/praatP.h`/ |
| 38 | #include "praatM.h"cxx . . $ `<file>/sys/praatM.h`/ |
| 39 | #include "praat_script.h"cxx . . $ `<file>/sys/praat_script.h`/ |
| 40 | #include "site.h"cxx . . $ `<file>/sys/site.h`/ |
| 41 | #include "machine.h"cxx . . $ `<file>/sys/machine.h`/ |
| 42 | #include "Printer.h"cxx . . $ `<file>/sys/Printer.h`/ |
| 43 | #include "ScriptEditor.h"cxx . . $ `<file>/sys/ScriptEditor.h`/ |
| 44 | #include "NotebookEditor.h"cxx . . $ `<file>/sys/NotebookEditor.h`/ |
| 45 | #include "Strings_.h"cxx . . $ `<file>/sys/Strings_.h`/ |
| 46 | #include "../kar/UnicodeData.h"cxx . . $ `<file>/kar/UnicodeData.h`/ |
| 47 | #include "InfoEditor.h"cxx . . $ `<file>/sys/InfoEditor.h`/ |
| 48 | |
| 49 | Thing_implementcxx . . $ `sys/Thing.h:65:9`! (Praat_Command, Thing, 0); |
| 50 | |
| 51 | #define EDITORcxx . . $ `sys/praat.cpp:51:9`! theCurrentPraatObjects -> list [IOBJECT]. editors |
| 52 | |
| 53 | #define WINDOW_WIDTHcxx . . $ `sys/praat.cpp:53:9`! 520 |
| 54 | #define WINDOW_HEIGHTcxx . . $ `sys/praat.cpp:54:9`! 700 |
| 55 | |
| 56 | /* |
| 57 | Six globals, not `inline` (see praat.h 2021-04-15). |
| 58 | */ |
| 59 | structPraatApplicationcxx . . $ structPraatApplication# theForegroundPraatApplicationcxx . . $ theForegroundPraatApplication.; |
| 60 | PraatApplicationcxx . . $ PraatApplication# theCurrentPraatApplicationcxx . . $ theCurrentPraatApplication. = & theForegroundPraatApplicationcxx . . $ theForegroundPraatApplication.; |
| 61 | structPraatObjectscxx . . $ structPraatObjects# theForegroundPraatObjectscxx . . $ theForegroundPraatObjects.; |
| 62 | PraatObjectscxx . . $ PraatObjects# theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. = & theForegroundPraatObjectscxx . . $ theForegroundPraatObjects.; |
| 63 | structPraatPicturecxx . . $ structPraatPicture# theForegroundPraatPicturecxx . . $ theForegroundPraatPicture.; |
| 64 | PraatPicturecxx . . $ PraatPicture# theCurrentPraatPicturecxx . . $ theCurrentPraatPicture. = & theForegroundPraatPicturecxx . . $ theForegroundPraatPicture.; |
| 65 | |
| 66 | bool praat_commandsWithExternalSideEffectsAreAllowedcxx . . $ praat_commandsWithExternalSideEffectsAreAllowed(c9857a73d68e59ba). () { |
| 67 | return |
| 68 | theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. == & theForegroundPraatObjectscxx . . $ theForegroundPraatObjects. || |
| 69 | ! theCurrentPraatApplicationcxx . . $ theCurrentPraatApplication. -> manPagescxx . . $ structPraatApplication#manPages. || |
| 70 | theCurrentPraatApplicationcxx . . $ theCurrentPraatApplication. -> manPagescxx . . $ structPraatApplication#manPages. -> commandsWithExternalSideEffectsAreAllowedcxx . . $ structManPages#commandsWithExternalSideEffectsAreAllowed. |
| 71 | ; |
| 72 | }; |
| 73 | |
| 74 | static structMelderFoldercxx . . $ structMelderFolder# homeDircxx . . $ homeDir. { }; |
| 75 | |
| 76 | /* |
| 77 | * Melder_preferencesFolder: a folder containing preferences file, buttons file, message files, tracing file, plugins. |
| 78 | * Unix: /home/miep/.config/praat |
| 79 | * Windows: C:\Users\Miep\Praat |
| 80 | * MacOS: /Users/Miep/Library/Application Support/Praat |
| 81 | */ |
| 82 | // inline structMelderFolder Melder_preferencesFolder { }; // already declared in Melder_files.h (checked 2021-03-07) |
| 83 | |
| 84 | /* |
| 85 | * prefsFile: preferences file. |
| 86 | * Unix: /home/miep/.config/praat/Preferences.txt |
| 87 | * Windows: C:\Users\Miep\AppData\Roaming\Praat\Preferences.txt |
| 88 | * MacOS: /Users/Miep/Library/Application Support/Praat/Preferences.txt |
| 89 | */ |
| 90 | static structMelderFilecxx . . $ structMelderFile# prefsFile5cxx . . $ prefsFile5. { }, prefsFile7cxx . . $ prefsFile7. { }; |
| 91 | |
| 92 | /* |
| 93 | * buttonsFile: buttons file. |
| 94 | * Unix: /home/miep/.config/praat/Buttons.txt |
| 95 | * Windows: C:\Users\Miep\AppData\Roaming\Praat\Buttons.txt |
| 96 | * MacOS: /Users/Miep/Library/Application Support/Praat/Buttons.txt |
| 97 | */ |
| 98 | static structMelderFilecxx . . $ structMelderFile# buttonsFile5cxx . . $ buttonsFile5. { }, buttonsFile7cxx . . $ buttonsFile7. { }; |
| 99 | |
| 100 | /* |
| 101 | * tracingFile: tracing file. |
| 102 | * Unix: /home/miep/.config/praat/Tracing.txt |
| 103 | * Windows: C:\Users\Miep\AppData\Roaming\Praat\Tracing.txt |
| 104 | * MacOS: /Users/Miep/Library/Application Support/Praat/Tracing.txt |
| 105 | */ |
| 106 | static structMelderFilecxx . . $ structMelderFile# tracingFilecxx . . $ tracingFile. { }; |
| 107 | |
| 108 | /* |
| 109 | * messageFile: message file: where sendpraat or --send writes its message. |
| 110 | * Unix: /home/miep/.config/praat/Message.txt |
| 111 | * Windows: C:\Users\Miep\AppData\Roaming\Praat\Message.txt |
| 112 | * MacOS: /Users/Miep/Library/Application Support/Praat/Message.txt |
| 113 | */ |
| 114 | static structMelderFilecxx . . $ structMelderFile# messageFilecxx . . $ messageFile. { }; |
| 115 | #if defined (UNIXcxx . . $ `<built-in>:479:9`!) |
| 116 | static structMelderFilecxx . . $ structMelderFile# pidFilecxx . . $ pidFile. { }; // like /home/miep/.config/praat/pid |
| 117 | #endif |
| 118 | |
| 119 | static GuiListcxx . . $ GuiList# praatList_objectscxx . . $ praatList_objects.; |
| 120 | |
| 121 | /***** selection *****/ |
| 122 | |
| 123 | integercxx . . $ integer# praat_idOfSelectedcxx . . $ praat_idOfSelected(b92ee5db4de9c66b). (ClassInfocxx . . $ ClassInfo# klas, integercxx . . $ integer# inplace) { |
| 124 | integercxx . . $ integer# place = inplace, IOBJECT; |
| 125 | if (place == 0) |
| 126 | place = 1; |
| 127 | if (place > 0) { |
| 128 | WHEREcxx . . $ `sys/praat.h:198:9`! (SELECTEDcxx . . $ `sys/praat.h:200:9`! && (! klas || CLASScxx . . $ `sys/praat.h:202:9`! == klas)) { |
| 129 | if (place == 1) |
| 130 | return IDcxx . . $ `sys/praat.h:206:9`!; |
| 131 | place --; |
| 132 | } |
| 133 | } else { |
| 134 | WHERE_DOWNcxx . . $ `sys/praat.h:199:9`! (SELECTEDcxx . . $ `sys/praat.h:200:9`! && (! klas || CLASScxx . . $ `sys/praat.h:202:9`! == klas)) { |
| 135 | if (place == -1) |
| 136 | return IDcxx . . $ `sys/praat.h:206:9`!; |
| 137 | place ++; |
| 138 | } |
| 139 | } |
| 140 | if (inplace) |
| 141 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"No ", klas ? klas -> className : U"object", U" #", inplace, U" selected."); |
| 142 | else |
| 143 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"No ", klas ? klas -> className : U"object", U" selected."); |
| 144 | return 0; |
| 145 | } |
| 146 | |
| 147 | autoVECcxx . . $ autoVEC# praat_idsOfAllSelectedcxx . . $ praat_idsOfAllSelected(85815b18a910bd48). (ClassInfocxx . . $ ClassInfo# klas) { |
| 148 | autoVECcxx . . $ autoVEC# result = raw_VECcxx . . $ raw_VEC(e4395f764b859b1e). (praat_numberOfSelectedcxx . . $ praat_numberOfSelected(33e8b4a553c0cc95). (klas)); |
| 149 | integercxx . . $ integer# selectedObjectNumber = 0, IOBJECT; |
| 150 | WHEREcxx . . $ `sys/praat.h:198:9`! (SELECTEDcxx . . $ `sys/praat.h:200:9`! && (! klas || CLASScxx . . $ `sys/praat.h:202:9`! == klas)) |
| 151 | result [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).++ selectedObjectNumber] = IDcxx . . $ `sys/praat.h:206:9`!; |
| 152 | return resultcxx . . $ autovector#autovector(d33c649a3aceae2f).; |
| 153 | } |
| 154 | |
| 155 | autoSTRVECcxx . . $ autoSTRVEC# praat_namesOfAllSelectedcxx . . $ praat_namesOfAllSelected(71fc934e5b24e4c0). (ClassInfocxx . . $ ClassInfo# klas) { |
| 156 | autoSTRVECcxx . . $ autoSTRVEC# resultcxx . . $ _autostringautovector#_autostringautovector(1624ee8275b10bda). (praat_numberOfSelectedcxx . . $ praat_numberOfSelected(33e8b4a553c0cc95). (klas)); |
| 157 | integercxx . . $ integer# selectedObjectNumber = 0, IOBJECT; |
| 158 | WHEREcxx . . $ `sys/praat.h:198:9`! (SELECTEDcxx . . $ `sys/praat.h:200:9`! && (! klas || CLASScxx . . $ `sys/praat.h:202:9`! == klas)) |
| 159 | result [cxx . . $ _autostringautovector#`operator[]`(f191be2b65019068).++ selectedObjectNumber] =cxx . . $ _autostring#`operator=`(f562943cbc4bcf37). Melder_dupcxx . . $ Melder_dup(87bf156b1f548402). (klas ? NAMEcxx . . $ `sys/praat.h:208:9`! : FULL_NAMEcxx . . $ `sys/praat.h:205:9`!); |
| 160 | return resultcxx . . $ _autostringautovector#_autostringautovector(f820baba8b4ac957).; |
| 161 | } |
| 162 | |
| 163 | char32cxx . . $ char32# * praat_nameOfSelectedcxx . . $ praat_nameOfSelected(4d3fbba0fc83dc8c). (ClassInfocxx . . $ ClassInfo# klas, integercxx . . $ integer# inplace) { |
| 164 | integercxx . . $ integer# place = inplace, IOBJECT; |
| 165 | if (place == 0) |
| 166 | place = 1; |
| 167 | if (place > 0) { |
| 168 | WHEREcxx . . $ `sys/praat.h:198:9`! (SELECTEDcxx . . $ `sys/praat.h:200:9`! && (! klas || CLASScxx . . $ `sys/praat.h:202:9`! == klas)) { |
| 169 | if (place == 1) |
| 170 | return klas ? NAMEcxx . . $ `sys/praat.h:208:9`! : FULL_NAMEcxx . . $ `sys/praat.h:205:9`!; |
| 171 | place --; |
| 172 | } |
| 173 | } else { |
| 174 | WHERE_DOWNcxx . . $ `sys/praat.h:199:9`! (SELECTEDcxx . . $ `sys/praat.h:200:9`! && (! klas || CLASScxx . . $ `sys/praat.h:202:9`! == klas)) { |
| 175 | if (place == -1) |
| 176 | return klas ? NAMEcxx . . $ `sys/praat.h:208:9`! : FULL_NAMEcxx . . $ `sys/praat.h:205:9`!; |
| 177 | place ++; |
| 178 | } |
| 179 | } |
| 180 | if (inplace) |
| 181 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"No ", klas ? klas -> className : U"object", U" #", inplace, U" selected."); |
| 182 | else |
| 183 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"No ", klas ? klas -> className : U"object", U" selected."); |
| 184 | return nullptr; // failure, but never reached anyway |
| 185 | } |
| 186 | |
| 187 | integercxx . . $ integer# praat_numberOfSelectedcxx . . $ praat_numberOfSelected(33e8b4a553c0cc95). (ClassInfocxx . . $ ClassInfo# klas) { |
| 188 | if (! klas) |
| 189 | return theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> totalSelectioncxx . . $ structPraatObjects#totalSelection.; |
| 190 | integercxx . . $ integer# readableClassId = klas -> sequentialUniqueIdOfReadableClasscxx . . $ structClassInfo#sequentialUniqueIdOfReadableClass.; |
| 191 | if (readableClassId == 0) |
| 192 | Melder_crashcxx . . $ `melder/melder_error.h:98:9`! (U"No sequential unique ID for class ", klas -> className, U" (numberOfSelected)."); |
| 193 | return theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> numberOfSelectedcxx . . $ structPraatObjects#numberOfSelected. [readableClassId]; |
| 194 | } |
| 195 | |
| 196 | void praat_deselectcxx . . $ praat_deselect(1624ee8275b10bda). (integercxx . . $ integer# IOBJECT) { |
| 197 | if (! SELECTEDcxx . . $ `sys/praat.h:200:9`!) |
| 198 | return; |
| 199 | SELECTEDcxx . . $ `sys/praat.h:200:9`! = false; |
| 200 | theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> totalSelectioncxx . . $ structPraatObjects#totalSelection. -= 1; |
| 201 | integercxx . . $ integer# readableClassId = theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> listcxx . . $ structPraatObjects#list. [IOBJECT]. objectcxx . . $ structPraat_Object#object. -> classInfocxx . . $ structThing#classInfo. -> sequentialUniqueIdOfReadableClasscxx . . $ structClassInfo#sequentialUniqueIdOfReadableClass.; |
| 202 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (readableClassId != 0); |
| 203 | theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> numberOfSelectedcxx . . $ structPraatObjects#numberOfSelected. [readableClassId] -= 1; |
| 204 | if (! theCurrentPraatApplicationcxx . . $ theCurrentPraatApplication. -> batchcxx . . $ structPraatApplication#batch. && ! Melder_backgroundingcxx . . $ Melder_backgrounding.) { |
| 205 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"deselecting object ", IOBJECT); |
| 206 | GuiList_deselectItemcxx . . $ GuiList_deselectItem(f9b5f8b1da8fd2dd). (praatList_objectscxx . . $ praatList_objects., IOBJECT); |
| 207 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"deselected object ", IOBJECT); |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | void praat_deselectAllcxx . . $ praat_deselectAll(49f6e7a06ebc5aa8). () { |
| 212 | integercxx . . $ integer# IOBJECT; |
| 213 | WHEREcxx . . $ `sys/praat.h:198:9`! (1) |
| 214 | praat_deselectcxx . . $ praat_deselect(1624ee8275b10bda). (IOBJECT); |
| 215 | } |
| 216 | |
| 217 | void praat_selectcxx . . $ praat_select(1624ee8275b10bda). (integercxx . . $ integer# IOBJECT) { |
| 218 | if (SELECTEDcxx . . $ `sys/praat.h:200:9`!) |
| 219 | return; |
| 220 | SELECTEDcxx . . $ `sys/praat.h:200:9`! = true; |
| 221 | theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> totalSelectioncxx . . $ structPraatObjects#totalSelection. += 1; |
| 222 | Thingcxx . . $ Thing# object = theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> listcxx . . $ structPraatObjects#list. [IOBJECT]. objectcxx . . $ structPraat_Object#object.; |
| 223 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (object); |
| 224 | integercxx . . $ integer# readableClassId = object -> classInfocxx . . $ structThing#classInfo. -> sequentialUniqueIdOfReadableClasscxx . . $ structClassInfo#sequentialUniqueIdOfReadableClass.; |
| 225 | if (readableClassId == 0) |
| 226 | Melder_crashcxx . . $ `melder/melder_error.h:98:9`! (U"No sequential unique ID for class ", object -> classInfo -> className, U" (selectObject)."); |
| 227 | theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> numberOfSelectedcxx . . $ structPraatObjects#numberOfSelected. [readableClassId] += 1; |
| 228 | if (! theCurrentPraatApplicationcxx . . $ theCurrentPraatApplication. -> batchcxx . . $ structPraatApplication#batch. && ! Melder_backgroundingcxx . . $ Melder_backgrounding.) |
| 229 | GuiList_selectItemcxx . . $ GuiList_selectItem(f9b5f8b1da8fd2dd). (praatList_objectscxx . . $ praatList_objects., IOBJECT); |
| 230 | } |
| 231 | |
| 232 | void praat_selectAllcxx . . $ praat_selectAll(49f6e7a06ebc5aa8). () { |
| 233 | integercxx . . $ integer# IOBJECT; |
| 234 | WHEREcxx . . $ `sys/praat.h:198:9`! (true) |
| 235 | praat_selectcxx . . $ praat_select(1624ee8275b10bda). (IOBJECT); |
| 236 | } |
| 237 | |
| 238 | void praat_list_backgroundcxx . . $ praat_list_background(49f6e7a06ebc5aa8). () { |
| 239 | integercxx . . $ integer# IOBJECT; |
| 240 | WHEREcxx . . $ `sys/praat.h:198:9`! (SELECTEDcxx . . $ `sys/praat.h:200:9`!) |
| 241 | GuiList_deselectItemcxx . . $ GuiList_deselectItem(f9b5f8b1da8fd2dd). (praatList_objectscxx . . $ praatList_objects., IOBJECT); |
| 242 | } |
| 243 | void praat_list_foregroundcxx . . $ praat_list_foreground(49f6e7a06ebc5aa8). () { |
| 244 | integercxx . . $ integer# IOBJECT; |
| 245 | WHEREcxx . . $ `sys/praat.h:198:9`! (SELECTEDcxx . . $ `sys/praat.h:200:9`!) |
| 246 | GuiList_selectItemcxx . . $ GuiList_selectItem(f9b5f8b1da8fd2dd). (praatList_objectscxx . . $ praatList_objects., IOBJECT); |
| 247 | } |
| 248 | |
| 249 | autoCollectioncxx . . $ autoCollection# praat_getSelectedObjectscxx . . $ praat_getSelectedObjects(859008c51157a0cd). () { |
| 250 | autoCollectioncxx . . $ autoCollection# thee = Collection_createcxx . . $ Collection_create(859008c51157a0cd). (); |
| 251 | integercxx . . $ integer# IOBJECT; |
| 252 | LOOPcxx . . $ `sys/praat.h:201:9`! { |
| 253 | iam_LOOPcxx . . $ `sys/praat.h:197:9`! (Daata); |
| 254 | thycxx . . $ `melder/melder.h:45:9`! addItem_refcxx . . $ CollectionOf#addItem_ref(ebd0a1552f8ce24f). (me); |
| 255 | } |
| 256 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 257 | } |
| 258 | |
| 259 | char32cxx . . $ char32# *praat_namecxx . . $ praat_name(84072f118ef1d63c). (integercxx . . $ integer# IOBJECT) { return str32chrcxx . . $ str32chr(328a9ede0fba853a). (FULL_NAMEcxx . . $ `sys/praat.h:205:9`!, U' ') + 1; } |
| 260 | |
| 261 | void praat_write_docxx . . $ praat_write_do(dd78e4d327935865). (UiFormcxx . . $ UiForm# dia, conststring32cxx . . $ conststring32# extension) { |
| 262 | static MelderStringcxx . . $ MelderString# defaultFileName; |
| 263 | if (extension && str32chrcxx . . $ str32chr(328a9ede0fba853a). (extension, U'.')) { |
| 264 | /* |
| 265 | Apparently, the "extension" is a complete file name. |
| 266 | This should be used as the default file name. |
| 267 | (This case typically occurs when saving a picture.) |
| 268 | */ |
| 269 | MelderString_copycxx . . $ MelderString_copy(65be51a793e0ff96). (& defaultFileName, extension); |
| 270 | } else { |
| 271 | /* |
| 272 | Apparently, the "extension" is not a complete file name. |
| 273 | We are expected to prepend the "extension" with the name of a selected object. |
| 274 | */ |
| 275 | integercxx . . $ integer# IOBJECT, found = 0; |
| 276 | Daatacxx . . $ Daata# data = nullptr; |
| 277 | WHEREcxx . . $ `sys/praat.h:198:9`! (SELECTEDcxx . . $ `sys/praat.h:200:9`!) { |
| 278 | if (! data) |
| 279 | data = (Daatacxx . . $ Daata#) OBJECTcxx . . $ `sys/praat.h:203:9`!; |
| 280 | found += 1; |
| 281 | } |
| 282 | if (found == 1) { |
| 283 | MelderString_copycxx . . $ MelderString_copy(65be51a793e0ff96). (& defaultFileName, data -> namecxx . . $ structThing#name..getcxx . . $ _autostring#get(5a2a78a048fb49a8).()); |
| 284 | if (defaultFileName.lengthcxx . . $ MelderString#length. > 200) { |
| 285 | defaultFileName.stringcxx . . $ MelderString#string. [200] = U'\0'; |
| 286 | defaultFileName.lengthcxx . . $ MelderString#length. = 200; |
| 287 | } |
| 288 | MelderString_appendcxx . . $ MelderString_append(65be51a793e0ff96). (& defaultFileName, U".", extension ? extension : Thing_classNamecxx . . $ Thing_className(fbb3dc34e3ef688d). (data)); |
| 289 | } else if (! extension) { |
| 290 | MelderString_copycxx . . $ MelderString_copy(65be51a793e0ff96). (& defaultFileName, U"praat.Collection"); |
| 291 | } else { |
| 292 | MelderString_copycxx . . $ MelderString_copy(65be51a793e0ff96). (& defaultFileName, U"praat.", extension); |
| 293 | } |
| 294 | } |
| 295 | UiOutfile_docxx . . $ UiOutfile_do(dd78e4d327935865). (dia, defaultFileName.stringcxx . . $ MelderString#string.); |
| 296 | } |
| 297 | |
| 298 | static void removeAllReferencesToMoribundEditorcxx . . $ removeAllReferencesToMoribundEditor(c0154a85f79216c7). (Editorcxx . . $ Editor# editor) { |
| 299 | /* |
| 300 | Remove all references to this editor. |
| 301 | It may be editing multiple objects. |
| 302 | */ |
| 303 | for (integercxx . . $ integer# iobject = 1; iobject <= theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> ncxx . . $ structPraatObjects#n.; iobject ++) |
| 304 | for (integercxx . . $ integer# ieditor = 0; ieditor < praat_MAXNUM_EDITORScxx . . $ `sys/praat.h:121:9`!; ieditor ++) |
| 305 | if (theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> listcxx . . $ structPraatObjects#list. [iobject]. editorscxx . . $ structPraat_Object#editors. [ieditor] == editor) |
| 306 | theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> listcxx . . $ structPraatObjects#list. [iobject]. editorscxx . . $ structPraat_Object#editors. [ieditor] = nullptr; |
| 307 | } |
| 308 | |
| 309 | /** |
| 310 | Remove the "object" from the list, |
| 311 | killing everything that has to do with the selection. |
| 312 | */ |
| 313 | static void praat_removecxx . . $ praat_remove(f153f132b2bc41c2). (integercxx . . $ integer# iobject, bool removeVisibly) { |
| 314 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (iobject >= 1 && iobject <= theCurrentPraatObjects -> n); |
| 315 | if (theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> listcxx . . $ structPraatObjects#list. [iobject]. isBeingCreatedcxx . . $ structPraat_Object#isBeingCreated.) { |
| 316 | theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> listcxx . . $ structPraatObjects#list. [iobject]. isBeingCreatedcxx . . $ structPraat_Object#isBeingCreated. = false; |
| 317 | theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> totalBeingCreatedcxx . . $ structPraatObjects#totalBeingCreated. --; |
| 318 | } |
| 319 | if (removeVisibly) |
| 320 | praat_deselectcxx . . $ praat_deselect(1624ee8275b10bda). (iobject); |
| 321 | |
| 322 | /* |
| 323 | To prevent synchronization problems, kill editors before killing the data. |
| 324 | */ |
| 325 | for (integercxx . . $ integer# ieditor = 0; ieditor < praat_MAXNUM_EDITORScxx . . $ `sys/praat.h:121:9`!; ieditor ++) { |
| 326 | Editorcxx . . $ Editor# editor = theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> listcxx . . $ structPraatObjects#list. [iobject]. editorscxx . . $ structPraat_Object#editors. [ieditor]; // save this one reference |
| 327 | if (editor) { |
| 328 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"remove references to editor ", ieditor); |
| 329 | removeAllReferencesToMoribundEditorcxx . . $ removeAllReferencesToMoribundEditor(c0154a85f79216c7). (editor); |
| 330 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"forget editor ", ieditor); |
| 331 | if (removeVisibly) |
| 332 | forgetcxx . . $ `sys/Thing.h:158:9`! (editor); // TODO: doesn't this call removeAllReferencesToMoribundEditor() again? |
| 333 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"forgotten editor ", ieditor); |
| 334 | } |
| 335 | } |
| 336 | MelderFile_setToNullcxx . . $ MelderFile_setToNull(1145552d769d7b5d). (& theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> listcxx . . $ structPraatObjects#list. [iobject]. filecxx . . $ structPraat_Object#file.); |
| 337 | theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> listcxx . . $ structPraatObjects#list. [iobject]. namecxx . . $ structPraat_Object#name.. resetcxx . . $ _autostring#reset(49f6e7a06ebc5aa8).(); |
| 338 | forgetcxx . . $ `sys/Thing.h:158:9`! (theCurrentPraatObjects -> list [iobject]. object); // note: this might save a file-based object to file |
| 339 | } |
| 340 | |
| 341 | void praat_cleanUpNamecxx . . $ praat_cleanUpName(d6cb0530b34b3d29). (char32cxx . . $ char32# *name) { |
| 342 | /* |
| 343 | Replaces spaces and special characters by underscores. |
| 344 | */ |
| 345 | for (; *name; name ++) |
| 346 | if (str32chrcxx . . $ str32chr(328a9ede0fba853a). (U" ,.:;\\/()[]{}~`\'<>*&^%#@!?$\"|", *name)) |
| 347 | *name = U'_'; |
| 348 | } |
| 349 | |
| 350 | /***** objects + commands *****/ |
| 351 | |
| 352 | static void praat_new_unpackCollectioncxx . . $ praat_new_unpackCollection(4c2896f65547a572). (autoCollectioncxx . . $ autoCollection# me, const char32cxx . . $ char32#* myName) { |
| 353 | for (integercxx . . $ integer# idata = 1; idata <= mycxx . . $ `melder/melder.h:44:9`! sizecxx . . $ CollectionOf#size.; idata ++) { |
| 354 | autoDaatacxx . . $ autoDaata# objectcxx . . $ autoSomeThing#autoSomeThing(49f6e7a06ebc5aa8).; |
| 355 | object. adoptFromAmbiguousOwnercxx . . $ autoSomeThing#adoptFromAmbiguousOwner(6f97683fca3ece44). ((Daatacxx . . $ Daata#) mycxx . . $ `melder/melder.h:44:9`! atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).idata]); |
| 356 | mycxx . . $ `melder/melder.h:44:9`! atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).idata] = nullptr; // disown; once the elements are autoThings, the move will handle this |
| 357 | const conststring32cxx . . $ conststring32# name = ( object ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). namecxx . . $ structThing#name. ? object ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). namecxx . . $ structThing#name..getcxx . . $ _autostring#get(5a2a78a048fb49a8).() : myName ); |
| 358 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (name); |
| 359 | praat_newcxx . . $ praat_new(1e9b2ae553a98dd1). (objectcxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f)..movecxx . . $ autoSomeThing#move(25acc3554b7d1642).(), namecxx . . $ MelderArg#MelderArg(ff00d524ab0355ec).); // recurse |
| 360 | } |
| 361 | } |
| 362 | |
| 363 | void praat_newWithFilecxx . . $ praat_newWithFile(edccf1f4beee5182). (autoDaatacxx . . $ autoDaata# me, MelderFilecxx . . $ MelderFile# file, conststring32cxx . . $ conststring32# myName) { |
| 364 | if (! me) |
| 365 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"No object was put into the list."); |
| 366 | |
| 367 | if (mycxx . . $ `melder/melder.h:44:9`! classInfocxx . . $ structThing#classInfo. == classCollectioncxx . . $ classCollection.) { |
| 368 | praat_new_unpackCollectioncxx . . $ praat_new_unpackCollection(4c2896f65547a572). (me.static_cast_movecxx . . $ autoSomeThing#static_cast_move(8f979c7064dbabcf). <structCollectioncxx . . $ structCollection#>(), myName); |
| 369 | return; |
| 370 | } |
| 371 | |
| 372 | autoMelderStringcxx . . $ autoMelderString# namecxx . . $ autoMelderString#autoMelderString(49f6e7a06ebc5aa8)., givenNamecxx . . $ autoMelderString#autoMelderString(49f6e7a06ebc5aa8).; |
| 373 | if (myName && myName [0]) { |
| 374 | MelderString_copycxx . . $ MelderString_copy(65be51a793e0ff96). (& givenName, myName); |
| 375 | /* |
| 376 | Remove extension. |
| 377 | */ |
| 378 | char32cxx . . $ char32# *p = str32rchrcxx . . $ str32rchr(328a9ede0fba853a). (givenName.stringcxx . . $ MelderString#string., U'.'); |
| 379 | if (p) |
| 380 | *p = U'\0'; |
| 381 | } else { |
| 382 | MelderString_copycxx . . $ MelderString_copy(65be51a793e0ff96). (& givenName, mycxx . . $ `melder/melder.h:44:9`! namecxx . . $ structThing#name. && mycxx . . $ `melder/melder.h:44:9`! namecxx . . $ structThing#name. [cxx . . $ _autostring#`operator[]`(b190d49faf30c5be).0] ? mycxx . . $ `melder/melder.h:44:9`! namecxx . . $ structThing#name..getcxx . . $ _autostring#get(5a2a78a048fb49a8).() : U"untitled"); |
| 383 | } |
| 384 | praat_cleanUpNamecxx . . $ praat_cleanUpName(d6cb0530b34b3d29). (givenName.stringcxx . . $ MelderString#string.); |
| 385 | MelderString_appendcxx . . $ MelderString_append(65be51a793e0ff96). (& name, Thing_classNamecxx . . $ Thing_className(fbb3dc34e3ef688d). (me.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).()), U" ", givenName.stringcxx . . $ MelderString#string.); |
| 386 | |
| 387 | if (theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> ncxx . . $ structPraatObjects#n. == praat_MAXNUM_OBJECTScxx . . $ `sys/praat.h:134:9`!) { |
| 388 | //forget (me); |
| 389 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"The Object Window cannot contain more than ", praat_MAXNUM_OBJECTScxx . . $ `sys/praat.h:134:9`!, U" objects. You could remove some objects."); |
| 390 | } |
| 391 | |
| 392 | integercxx . . $ integer# IOBJECT = ++ theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> ncxx . . $ structPraatObjects#n.; |
| 393 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (FULL_NAMEcxx . . $ `sys/praat.h:205:9`! == nullptr); |
| 394 | theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> listcxx . . $ structPraatObjects#list. [IOBJECT]. namecxx . . $ structPraat_Object#name. =cxx . . $ _autostring#`operator=`(f562943cbc4bcf37). Melder_dup_fcxx . . $ Melder_dup_f(87bf156b1f548402). (name.stringcxx . . $ MelderString#string.); // all right to crash if out of memory |
| 395 | ++ theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> sequentialUniqueIdOfLatestObjectInListcxx . . $ structPraatObjects#sequentialUniqueIdOfLatestObjectInList.; |
| 396 | |
| 397 | if (! theCurrentPraatApplicationcxx . . $ theCurrentPraatApplication. -> batchcxx . . $ structPraatApplication#batch.) // put a new object on the screen, at the bottom of the list |
| 398 | GuiList_insertItemcxx . . $ GuiList_insertItem(896610c612ff86cf). ( |
| 399 | praatList_objectscxx . . $ praatList_objects., |
| 400 | Melder_catcxx . . $ Melder_cat(7fbf27f4d367f442). (theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> sequentialUniqueIdOfLatestObjectInListcxx . . $ structPraatObjects#sequentialUniqueIdOfLatestObjectInList., U". ", name.stringcxx . . $ MelderString#string.), |
| 401 | theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> ncxx . . $ structPraatObjects#n. |
| 402 | ); |
| 403 | CLASScxx . . $ `sys/praat.h:202:9`! = mycxx . . $ `melder/melder.h:44:9`! classInfocxx . . $ structThing#classInfo.; |
| 404 | OBJECTcxx . . $ `sys/praat.h:203:9`! = me.releaseToAmbiguousOwnercxx . . $ autoSomeThing#releaseToAmbiguousOwner(258ee1c9e0a18a5c).(); // FIXME: should be move() |
| 405 | SELECTEDcxx . . $ `sys/praat.h:200:9`! = false; |
| 406 | for (int ieditor = 0; ieditor < praat_MAXNUM_EDITORScxx . . $ `sys/praat.h:121:9`!; ieditor ++) |
| 407 | EDITORcxx . . $ `sys/praat.cpp:51:9`! [ieditor] = nullptr; |
| 408 | if (file) |
| 409 | MelderFile_copycxx . . $ MelderFile_copy(b298201f6d539a65). (file, & theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> listcxx . . $ structPraatObjects#list. [IOBJECT]. filecxx . . $ structPraat_Object#file.); |
| 410 | else |
| 411 | MelderFile_setToNullcxx . . $ MelderFile_setToNull(1145552d769d7b5d). (& theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> listcxx . . $ structPraatObjects#list. [IOBJECT]. filecxx . . $ structPraat_Object#file.); |
| 412 | IDcxx . . $ `sys/praat.h:206:9`! = theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> sequentialUniqueIdOfLatestObjectInListcxx . . $ structPraatObjects#sequentialUniqueIdOfLatestObjectInList.; |
| 413 | theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> listcxx . . $ structPraatObjects#list. [IOBJECT]. isBeingCreatedcxx . . $ structPraat_Object#isBeingCreated. = true; |
| 414 | Thing_setNamecxx . . $ Thing_setName(b5a42e5e01c267b5). (OBJECTcxx . . $ `sys/praat.h:203:9`!, givenName.stringcxx . . $ MelderString#string.); |
| 415 | theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> totalBeingCreatedcxx . . $ structPraatObjects#totalBeingCreated. ++; |
| 416 | } |
| 417 | |
| 418 | static MelderStringcxx . . $ MelderString# thePraatNewNamecxx . . $ thePraatNewName.; |
| 419 | void praat_newcxx . . $ praat_new(90806586bd778ea4). (autoDaatacxx . . $ autoDaata# me) { |
| 420 | praat_newWithFilecxx . . $ praat_newWithFile(edccf1f4beee5182). (mecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f)..movecxx . . $ autoSomeThing#move(25acc3554b7d1642).(), nullptr, U""); |
| 421 | } |
| 422 | void praat_newcxx . . $ praat_new(1e9b2ae553a98dd1). (autoDaatacxx . . $ autoDaata# me, const MelderArgcxx . . $ MelderArg#& arg) { |
| 423 | praat_newWithFilecxx . . $ praat_newWithFile(edccf1f4beee5182). (mecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f)..movecxx . . $ autoSomeThing#move(25acc3554b7d1642).(), nullptr, arg._argcxx . . $ MelderArg#_arg.); |
| 424 | } |
| 425 | void praat_newcxx . . $ praat_new(7e14453ab0f22ea). (autoDaatacxx . . $ autoDaata# me, |
| 426 | const MelderArgcxx . . $ MelderArg#& arg1, const MelderArgcxx . . $ MelderArg#& arg2, const MelderArgcxx . . $ MelderArg#& arg3, |
| 427 | const MelderArgcxx . . $ MelderArg#& arg4, const MelderArgcxx . . $ MelderArg#& arg5) |
| 428 | { |
| 429 | MelderString_copycxx . . $ MelderString_copy(65be51a793e0ff96). (& thePraatNewNamecxx . . $ thePraatNewName., arg1._argcxx . . $ MelderArg#_arg., arg2._argcxx . . $ MelderArg#_arg., arg3._argcxx . . $ MelderArg#_arg., arg4._argcxx . . $ MelderArg#_arg., arg5._argcxx . . $ MelderArg#_arg.); |
| 430 | praat_newcxx . . $ praat_new(1e9b2ae553a98dd1). (mecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f)..movecxx . . $ autoSomeThing#move(25acc3554b7d1642).(), thePraatNewNamecxx . . $ MelderArg#MelderArg(ff00d524ab0355ec)..stringcxx . . $ MelderString#string.); |
| 431 | } |
| 432 | |
| 433 | void praat_updateSelectioncxx . . $ praat_updateSelection(49f6e7a06ebc5aa8). () { |
| 434 | if (theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> totalBeingCreatedcxx . . $ structPraatObjects#totalBeingCreated. > 0) { |
| 435 | integercxx . . $ integer# IOBJECT; |
| 436 | praat_deselectAllcxx . . $ praat_deselectAll(49f6e7a06ebc5aa8). (); |
| 437 | WHEREcxx . . $ `sys/praat.h:198:9`! (theCurrentPraatObjects -> list [IOBJECT]. isBeingCreated) { |
| 438 | praat_selectcxx . . $ praat_select(1624ee8275b10bda). (IOBJECT); |
| 439 | theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> listcxx . . $ structPraatObjects#list. [IOBJECT]. isBeingCreatedcxx . . $ structPraat_Object#isBeingCreated. = false; |
| 440 | } |
| 441 | theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> totalBeingCreatedcxx . . $ structPraatObjects#totalBeingCreated. = 0; |
| 442 | praat_showcxx . . $ praat_show(49f6e7a06ebc5aa8). (); |
| 443 | } |
| 444 | } |
| 445 | |
| 446 | static void gui_cb_list_selectionChangedcxx . . $ gui_cb_list_selectionChanged(a20089e6fc8b6268). (Thingcxx . . $ Thing# /* boss */, GuiList_SelectionChangedEventcxx . . $ GuiList_SelectionChangedEvent# event) { |
| 447 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (event -> list == praatList_objects); |
| 448 | integercxx . . $ integer# IOBJECT; |
| 449 | bool first = true; |
| 450 | WHEREcxx . . $ `sys/praat.h:198:9`! (SELECTEDcxx . . $ `sys/praat.h:200:9`!) { |
| 451 | SELECTEDcxx . . $ `sys/praat.h:200:9`! = false; |
| 452 | integercxx . . $ integer# readableClassId = theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> listcxx . . $ structPraatObjects#list. [IOBJECT]. objectcxx . . $ structPraat_Object#object. -> classInfocxx . . $ structThing#classInfo. -> sequentialUniqueIdOfReadableClasscxx . . $ structClassInfo#sequentialUniqueIdOfReadableClass.; |
| 453 | theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> numberOfSelectedcxx . . $ structPraatObjects#numberOfSelected. [readableClassId] --; |
| 454 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (theCurrentPraatObjects -> numberOfSelected [readableClassId] >= 0); |
| 455 | } |
| 456 | theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> totalSelectioncxx . . $ structPraatObjects#totalSelection. = 0; |
| 457 | autoINTVECcxx . . $ autoINTVEC# selected = GuiList_getSelectedPositionscxx . . $ GuiList_getSelectedPositions(21bc371a31941fa7). (praatList_objectscxx . . $ praatList_objects.); |
| 458 | for (integercxx . . $ integer# iselected = 1; iselected <= selected.sizecxx . . $ autovector#size.; iselected ++) { |
| 459 | IOBJECT = selected [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iselected]; |
| 460 | SELECTEDcxx . . $ `sys/praat.h:200:9`! = true; |
| 461 | integercxx . . $ integer# readableClassId = theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> listcxx . . $ structPraatObjects#list. [IOBJECT]. objectcxx . . $ structPraat_Object#object. -> classInfocxx . . $ structThing#classInfo. -> sequentialUniqueIdOfReadableClasscxx . . $ structClassInfo#sequentialUniqueIdOfReadableClass.; |
| 462 | theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> numberOfSelectedcxx . . $ structPraatObjects#numberOfSelected. [readableClassId] ++; |
| 463 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (theCurrentPraatObjects -> numberOfSelected [readableClassId] > 0); |
| 464 | UiHistory_writecxx . . $ UiHistory_write(ff00d524ab0355ec). (first ? U"\nselectObject: \"" : U"\nplusObject: \""); |
| 465 | UiHistory_write_expandQuotescxx . . $ UiHistory_write_expandQuotes(ff00d524ab0355ec). (FULL_NAMEcxx . . $ `sys/praat.h:205:9`!); |
| 466 | UiHistory_writecxx . . $ UiHistory_write(ff00d524ab0355ec). (U"\""); |
| 467 | first = false; |
| 468 | theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> totalSelectioncxx . . $ structPraatObjects#totalSelection. += 1; |
| 469 | } |
| 470 | praat_showcxx . . $ praat_show(49f6e7a06ebc5aa8). (); |
| 471 | } |
| 472 | |
| 473 | void praat_list_renameAndSelectcxx . . $ praat_list_renameAndSelect(cfe533a552fd45e9). (integercxx . . $ integer# position, conststring32cxx . . $ conststring32# name) { |
| 474 | if (! theCurrentPraatApplicationcxx . . $ theCurrentPraatApplication. -> batchcxx . . $ structPraatApplication#batch.) { |
| 475 | GuiList_replaceItemcxx . . $ GuiList_replaceItem(896610c612ff86cf). (praatList_objectscxx . . $ praatList_objects., name, position); // void if name equal |
| 476 | if (! Melder_backgroundingcxx . . $ Melder_backgrounding.) |
| 477 | GuiList_selectItemcxx . . $ GuiList_selectItem(f9b5f8b1da8fd2dd). (praatList_objectscxx . . $ praatList_objects., position); |
| 478 | } |
| 479 | } |
| 480 | |
| 481 | /***** objects *****/ |
| 482 | |
| 483 | void praat_name2cxx . . $ praat_name2(aec8d7b6328952bc). (char32cxx . . $ char32# *name, ClassInfocxx . . $ ClassInfo# klas1, ClassInfocxx . . $ ClassInfo# klas2) { |
| 484 | int i1 = 1; |
| 485 | while (theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> listcxx . . $ structPraatObjects#list. [i1]. isSelectedcxx . . $ structPraat_Object#isSelected. == 0 || theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> listcxx . . $ structPraatObjects#list. [i1]. klascxx . . $ structPraat_Object#klas. != klas1) |
| 486 | i1 ++; |
| 487 | int i2 = 1; |
| 488 | while (theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> listcxx . . $ structPraatObjects#list. [i2]. isSelectedcxx . . $ structPraat_Object#isSelected. == 0 || theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> listcxx . . $ structPraatObjects#list. [i2]. klascxx . . $ structPraat_Object#klas. != klas2) |
| 489 | i2 ++; |
| 490 | char32cxx . . $ char32# *name1 = str32chrcxx . . $ str32chr(328a9ede0fba853a). (theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> listcxx . . $ structPraatObjects#list. [i1]. namecxx . . $ structPraat_Object#name..getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), U' ') + 1; |
| 491 | char32cxx . . $ char32# *name2 = str32chrcxx . . $ str32chr(328a9ede0fba853a). (theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> listcxx . . $ structPraatObjects#list. [i2]. namecxx . . $ structPraat_Object#name..getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), U' ') + 1; |
| 492 | if (str32equcxx . . $ `melder/melder_str32.h:122:9`! (name1, name2)) |
| 493 | Melder_sprintcxx . . $ Melder_sprint(2b992b0fb5123bdf). (name,200, name1); |
| 494 | else |
| 495 | Melder_sprintcxx . . $ Melder_sprint(2b992b0fb5123bdf). (name,200, name1, U"_", name2); |
| 496 | } |
| 497 | |
| 498 | void praat_removeObjectcxx . . $ praat_removeObject(1624ee8275b10bda). (integercxx . . $ integer# i) { |
| 499 | praat_removecxx . . $ praat_remove(f153f132b2bc41c2). (i, true); // dangle |
| 500 | for (integercxx . . $ integer# j = i; j < theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> ncxx . . $ structPraatObjects#n.; j ++) |
| 501 | theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> listcxx . . $ structPraatObjects#list. [j] =cxx . . $ structPraat_Object#`operator=`(536a8a5bc220d8dd). stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26). (theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> listcxx . . $ structPraatObjects#list. [j + 1]); // undangle but create second references |
| 502 | theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> listcxx . . $ structPraatObjects#list. [theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> ncxx . . $ structPraatObjects#n.]. namecxx . . $ structPraat_Object#name.. resetcxx . . $ _autostring#reset(49f6e7a06ebc5aa8).(); |
| 503 | theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> listcxx . . $ structPraatObjects#list. [theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> ncxx . . $ structPraatObjects#n.]. objectcxx . . $ structPraat_Object#object. = nullptr; // undangle or remove second reference |
| 504 | theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> listcxx . . $ structPraatObjects#list. [theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> ncxx . . $ structPraatObjects#n.]. isSelectedcxx . . $ structPraat_Object#isSelected. = 0; |
| 505 | for (int ieditor = 0; ieditor < praat_MAXNUM_EDITORScxx . . $ `sys/praat.h:121:9`!; ieditor ++) |
| 506 | theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> listcxx . . $ structPraatObjects#list. [theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> ncxx . . $ structPraatObjects#n.]. editorscxx . . $ structPraat_Object#editors. [ieditor] = nullptr; // undangle or remove second reference |
| 507 | MelderFile_setToNullcxx . . $ MelderFile_setToNull(1145552d769d7b5d). (& theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> listcxx . . $ structPraatObjects#list. [theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> ncxx . . $ structPraatObjects#n.]. filecxx . . $ structPraat_Object#file.); // undangle or remove second reference |
| 508 | -- theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> ncxx . . $ structPraatObjects#n.; |
| 509 | if (! theCurrentPraatApplicationcxx . . $ theCurrentPraatApplication. -> batchcxx . . $ structPraatApplication#batch.) |
| 510 | GuiList_deleteItemcxx . . $ GuiList_deleteItem(f9b5f8b1da8fd2dd). (praatList_objectscxx . . $ praatList_objects., i); |
| 511 | } |
| 512 | |
| 513 | static void praat_exitcxx . . $ praat_exit(d4f767463ce0a6b3). (int exit_code) { |
| 514 | //Melder_setTracing (true); |
| 515 | integercxx . . $ integer# IOBJECT; |
| 516 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"destroy the picture window"); |
| 517 | praat_picture_exitcxx . . $ praat_picture_exit(49f6e7a06ebc5aa8). (); |
| 518 | praat_statistics_exitcxx . . $ praat_statistics_exit(49f6e7a06ebc5aa8). (); // record total memory use across sessions |
| 519 | |
| 520 | if (! praatPcxx . . $ praatP..ignorePreferenceFilescxx . . $ PraatP#ignorePreferenceFiles.) { |
| 521 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"stop receiving messages"); |
| 522 | #ifdef UNIXcxx . . $ `<built-in>:479:9`! |
| 523 | /* |
| 524 | We are going to delete the process ID ("pid") file, if it's ours. |
| 525 | We consider it ours if its process ID equals our own process ID |
| 526 | (no more checks are necessary; the pid file cannot have been created |
| 527 | by a different Praat instance in an earlier computer session, |
| 528 | because if we arrive here, we are sure to have created a new pid file |
| 529 | in the current computer session). |
| 530 | */ |
| 531 | if (! MelderFile_isNullcxx . . $ MelderFile_isNull(8f92cdf95b27d908). (& pidFilecxx . . $ pidFile.)) { |
| 532 | try { |
| 533 | /* |
| 534 | To see whether we own the pid file, |
| 535 | we look into it to see whether its pid equals our pid. |
| 536 | If not, then we are probably living in an old invocation of the program, |
| 537 | and the pid file was written by the latest invocation of the program, |
| 538 | which owns the pid (this means sendpraat can only send to the latest Praat if more than one are open). |
| 539 | */ |
| 540 | autofilecxx . . $ autofile# f = Melder_fopencxx . . $ autofile#autofile(8d4262d45fc644ab). (& pidFilecxx . . $ pidFile., "r"); |
| 541 | int pidOfLatestPraatInvocation; |
| 542 | if (fscanf (f, "%d", & pidOfLatestPraatInvocation) < 1) |
| 543 | throw MelderErrorcxx . . $ MelderError# (); |
| 544 | f.closecxx . . $ autofile#close(1145552d769d7b5d). (& pidFilecxx . . $ pidFile.); |
| 545 | int pidOfCurrentPraatIncoation = getpid (); |
| 546 | if (pidOfLatestPraatInvocation == pidOfCurrentPraatIncoation) |
| 547 | MelderFile_deletecxx . . $ MelderFile_delete(1145552d769d7b5d). (& pidFilecxx . . $ pidFile.); // ...then we own the pid file and can delete it |
| 548 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 549 | Melder_clearErrorcxx . . $ Melder_clearError(49f6e7a06ebc5aa8). (); // if the pid file is somehow missing or corrupted, we just ignore that |
| 550 | } |
| 551 | } |
| 552 | #endif |
| 553 | |
| 554 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"save the preferences"); |
| 555 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (str32equcxx . . $ `melder/melder_str32.h:122:9`! (Melder_double (1.5), U"1.5")); // refuse to write the preferences if the locale is wrong (even if tracing is on) |
| 556 | Preferences_write_icxx . . $ Preferences_write_i(1145552d769d7b5d). (& prefsFile7cxx . . $ prefsFile7.); |
| 557 | if (Melder_appVersioncxx . . $ Melder_appVersion(da6335ded91d79c2).() < 8000) { // allow the concurrent use of Praat 6 and 7, until Praat 8 |
| 558 | if (MelderFile_readablecxx . . $ MelderFile_readable(8f92cdf95b27d908). (& prefsFile7cxx . . $ prefsFile7.)) // If successful in writing the modern (Praat 7/8) settings file... |
| 559 | MelderFile_deletecxx . . $ MelderFile_delete(1145552d769d7b5d). (& prefsFile5cxx . . $ prefsFile5.); // ... then delete the obsolete (Praat 6) settings file. |
| 560 | } |
| 561 | |
| 562 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"save the script buttons"); |
| 563 | if (! theCurrentPraatApplicationcxx . . $ theCurrentPraatApplication. -> batchcxx . . $ structPraatApplication#batch.) { |
| 564 | try { |
| 565 | autoMelderStringcxx . . $ autoMelderString# buffercxx . . $ autoMelderString#autoMelderString(49f6e7a06ebc5aa8).; |
| 566 | MelderString_appendcxx . . $ MelderString_append(65be51a793e0ff96). (& buffer, U"# Buttons (1).\n"); |
| 567 | MelderString_appendcxx . . $ MelderString_append(65be51a793e0ff96). (& buffer, U"# This file is generated automatically when you quit the ", Melder_upperCaseAppNamecxx . . $ Melder_upperCaseAppName(1912f6684645c851).(), U" program.\n"); |
| 568 | MelderString_appendcxx . . $ MelderString_append(65be51a793e0ff96). (& buffer, U"# It contains the buttons that you added interactively to the fixed or dynamic menus,\n"); |
| 569 | MelderString_appendcxx . . $ MelderString_append(65be51a793e0ff96). (& buffer, U"# and the buttons that you hid or showed.\n\n"); |
| 570 | praat_saveAddedMenuCommandscxx . . $ praat_saveAddedMenuCommands(93db1090f27e5462). (& buffer); |
| 571 | praat_saveToggledMenuCommandscxx . . $ praat_saveToggledMenuCommands(93db1090f27e5462). (& buffer); |
| 572 | praat_saveAddedActionscxx . . $ praat_saveAddedActions(93db1090f27e5462). (& buffer); |
| 573 | praat_saveToggledActionscxx . . $ praat_saveToggledActions(93db1090f27e5462). (& buffer); |
| 574 | MelderFile_writeText_icxx . . $ MelderFile_writeText_i(4f26204211a3b413). (& buttonsFile7cxx . . $ buttonsFile7., buffer.stringcxx . . $ MelderString#string., kMelder_textOutputEncodingcxx . . $ kMelder_textOutputEncoding#::ASCII_THEN_UTF16cxx . . $ kMelder_textOutputEncoding#ASCII_THEN_UTF16.); |
| 575 | if (Melder_appVersioncxx . . $ Melder_appVersion(da6335ded91d79c2).() < 8000) { // allow the concurrent use of Praat 6 and 7, until Praat 8 |
| 576 | if (MelderFile_readablecxx . . $ MelderFile_readable(8f92cdf95b27d908). (& buttonsFile7cxx . . $ buttonsFile7.)) // If successful in writing the modern (Praat 7/8) buttons file... |
| 577 | MelderFile_deletecxx . . $ MelderFile_delete(1145552d769d7b5d). (& buttonsFile5cxx . . $ buttonsFile5.); // ... then delete the obsolete (Praat 6) buttons file. |
| 578 | } |
| 579 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 580 | Melder_clearErrorcxx . . $ Melder_clearError(49f6e7a06ebc5aa8). (); |
| 581 | } |
| 582 | } |
| 583 | } |
| 584 | |
| 585 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"flush the file-based objects"); |
| 586 | WHERE_DOWNcxx . . $ `sys/praat.h:199:9`! (! MelderFile_isNull (& theCurrentPraatObjects -> list [IOBJECT]. file)) { |
| 587 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"removing object based on file ", & theCurrentPraatObjects -> list [IOBJECT]. file); |
| 588 | praat_removecxx . . $ praat_remove(f153f132b2bc41c2). (IOBJECT, false); |
| 589 | } |
| 590 | |
| 591 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"leave the program"); |
| 592 | praat_menuCommands_exit_optimizeByLeakingcxx . . $ praat_menuCommands_exit_optimizeByLeaking(49f6e7a06ebc5aa8). (); // these calls are superflous if subsequently _Exit() is called instead of exit() |
| 593 | praat_actions_exit_optimizeByLeakingcxx . . $ praat_actions_exit_optimizeByLeaking(49f6e7a06ebc5aa8). (); |
| 594 | Preferences_exit_optimizeByLeakingcxx . . $ Preferences_exit_optimizeByLeaking(49f6e7a06ebc5aa8). (); |
| 595 | /* |
| 596 | OPTIMIZE with an exercise in self-documenting code |
| 597 | */ |
| 598 | constexpr bool weWouldLikeToOptimizeExitingSpeed = ((true)); |
| 599 | constexpr bool callingExitTimeDestructorsIsSlow = (true); |
| 600 | constexpr bool notCallingExitTimeDestructorsCausesCorrectBehaviour = (true); |
| 601 | constexpr bool weAreReallySureAboutThat = (true); |
| 602 | constexpr bool weWillUseUnderscoreExitInsteadOfExit = |
| 603 | weWouldLikeToOptimizeExitingSpeed && |
| 604 | callingExitTimeDestructorsIsSlow && |
| 605 | notCallingExitTimeDestructorsCausesCorrectBehaviour && |
| 606 | weAreReallySureAboutThat; |
| 607 | if ((weWillUseUnderscoreExitInsteadOfExit)) { |
| 608 | constexpr bool underscoreExitHasMoreSideEffectsThanJustNotCallingExitTimeDestructors = (true); |
| 609 | constexpr bool avoidOtherSideEffectsOfUnderscoreExit = |
| 610 | underscoreExitHasMoreSideEffectsThanJustNotCallingExitTimeDestructors; |
| 611 | if ((avoidOtherSideEffectsOfUnderscoreExit)) { |
| 612 | constexpr bool oneSideEffectIsThatOpenOutputFilesAreNotFlushed = true; |
| 613 | constexpr bool weShouldFlushAllOpenOutputFilesWhoseNonflushingWouldCauseIncorrectBehaviour = |
| 614 | oneSideEffectIsThatOpenOutputFilesAreNotFlushed; |
| 615 | if ((weShouldFlushAllOpenOutputFilesWhoseNonflushingWouldCauseIncorrectBehaviour)) { |
| 616 | constexpr bool stdoutIsOpen = (true); |
| 617 | constexpr bool stderrIsOpen = (true); |
| 618 | constexpr bool stdoutIsBufferedByDefault = true; |
| 619 | constexpr bool stderrIsBufferedByDefault = false; |
| 620 | constexpr bool weKnowThatSetbufHasNotBeenCalledOnStdout = (false); |
| 621 | constexpr bool weKnowThatSetbufHasNotBeenCalledOnStderr = (false); |
| 622 | constexpr bool stdoutHasCertainlyBeenFlushed = |
| 623 | ! stdoutIsBufferedByDefault && weKnowThatSetbufHasNotBeenCalledOnStdout; |
| 624 | constexpr bool stderrHasCertainlyBeenFlushed = |
| 625 | ! stderrIsBufferedByDefault && weKnowThatSetbufHasNotBeenCalledOnStderr; |
| 626 | constexpr bool notFlushingStdoutCouldCauseIncorrectBehaviour = |
| 627 | stdoutIsOpen && ! stdoutHasCertainlyBeenFlushed; |
| 628 | constexpr bool notFlushingStderrCouldCauseIncorrectBehaviour = |
| 629 | stderrIsOpen && ! stderrHasCertainlyBeenFlushed; |
| 630 | constexpr bool shouldFlushStdout = notFlushingStdoutCouldCauseIncorrectBehaviour; |
| 631 | constexpr bool shouldFlushStderr = notFlushingStderrCouldCauseIncorrectBehaviour; |
| 632 | if ((shouldFlushStdout)) |
| 633 | fflush (Melder_stdoutcxx . . $ Melder_stdout.); |
| 634 | if ((shouldFlushStderr)) |
| 635 | fflush (Melder_stderrcxx . . $ Melder_stderr.); |
| 636 | constexpr bool thereAreOtherOpenFiles = (false); |
| 637 | constexpr bool thereAreOtherOpenFilesWhoseNonflushingCouldCauseIncorrectBehaviour = |
| 638 | thereAreOtherOpenFiles; |
| 639 | if ((! thereAreOtherOpenFilesWhoseNonflushingCouldCauseIncorrectBehaviour)) {} |
| 640 | } |
| 641 | constexpr bool thereAreNoOtherSideEffectsBesideNotCallingExitDestructorsAndNotFlushingOpenFiles = (true); |
| 642 | if ((thereAreNoOtherSideEffectsBesideNotCallingExitDestructorsAndNotFlushingOpenFiles)) {} |
| 643 | } |
| 644 | _Exitcxx . . $ _Exit(44ed87f96534fad7). (exit_code); |
| 645 | } else { |
| 646 | exitcxx . . $ exit(44ed87f96534fad7). (exit_code); |
| 647 | } |
| 648 | } |
| 649 | |
| 650 | static void cb_Editor_destructioncxx . . $ cb_Editor_destruction(c0154a85f79216c7). (Editorcxx . . $ Editor# me) { |
| 651 | removeAllReferencesToMoribundEditorcxx . . $ removeAllReferencesToMoribundEditor(c0154a85f79216c7). (me); |
| 652 | } |
| 653 | |
| 654 | static void cb_Editor_dataChangedcxx . . $ cb_Editor_dataChanged(c0154a85f79216c7). (Editorcxx . . $ Editor# me) { |
| 655 | for (integercxx . . $ integer# iobject = 1; iobject <= theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> ncxx . . $ structPraatObjects#n.; iobject ++) { |
| 656 | /* |
| 657 | Am I editing this object? |
| 658 | */ |
| 659 | bool editingThisObject = false; |
| 660 | for (int ieditor = 0; ieditor < praat_MAXNUM_EDITORScxx . . $ `sys/praat.h:121:9`!; ieditor ++) |
| 661 | editingThisObject |= ( theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> listcxx . . $ structPraatObjects#list. [iobject]. editorscxx . . $ structPraat_Object#editors. [ieditor] == me ); |
| 662 | if (editingThisObject) { |
| 663 | /* |
| 664 | Notify all editors associated with this object, *including myself*. |
| 665 | But the receiver will be able to check whether the notification comes from self or not; |
| 666 | e.g. the DataEditor will react differently on a message from outside than on a message from inside. |
| 667 | (last checked 2022-09-30) |
| 668 | */ |
| 669 | for (int ieditor = 0; ieditor < praat_MAXNUM_EDITORScxx . . $ `sys/praat.h:121:9`!; ieditor ++) { |
| 670 | Editorcxx . . $ Editor# otherEditor = theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> listcxx . . $ structPraatObjects#list. [iobject]. editorscxx . . $ structPraat_Object#editors. [ieditor]; |
| 671 | if (otherEditor) |
| 672 | Editor_dataChangedcxx . . $ Editor_dataChanged(27010ae97811c311). (otherEditor, me); |
| 673 | } |
| 674 | } |
| 675 | } |
| 676 | } |
| 677 | |
| 678 | static void cb_Editor_publicationcxx . . $ cb_Editor_publication(87bd169f853965ad). (Editorcxx . . $ Editor# /* me */, autoDaatacxx . . $ autoDaata# publication) { |
| 679 | /* |
| 680 | The default publish callback. |
| 681 | Works nicely if the publisher invents a name. |
| 682 | */ |
| 683 | try { |
| 684 | praat_newcxx . . $ praat_new(1e9b2ae553a98dd1). (publicationcxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f)..movecxx . . $ autoSomeThing#move(25acc3554b7d1642).(), U""cxx . . $ MelderArg#MelderArg(ff00d524ab0355ec).); |
| 685 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 686 | Melder_flushErrorcxx . . $ Melder_flushError(49f6e7a06ebc5aa8). (); |
| 687 | } |
| 688 | praat_updateSelectioncxx . . $ praat_updateSelection(49f6e7a06ebc5aa8). (); |
| 689 | } |
| 690 | |
| 691 | void praat_installEditorcxx . . $ praat_installEditor(66c68acc57a91daa). (Editorcxx . . $ Editor# editor, integercxx . . $ integer# IOBJECT) { |
| 692 | if (! editor) |
| 693 | return; |
| 694 | for (integercxx . . $ integer# ieditor = 0; ieditor < praat_MAXNUM_EDITORScxx . . $ `sys/praat.h:121:9`!; ieditor ++) { |
| 695 | if (! EDITORcxx . . $ `sys/praat.cpp:51:9`! [ieditor]) { |
| 696 | EDITORcxx . . $ `sys/praat.cpp:51:9`! [ieditor] = editor; |
| 697 | Editor_setDestructionCallbackcxx . . $ Editor_setDestructionCallback(522aab46cb47898f). (editor, cb_Editor_destructioncxx . . $ MelderCallback#MelderCallback(fc624d2cd197112).); |
| 698 | Editor_setDataChangedCallbackcxx . . $ Editor_setDataChangedCallback(522aab46cb47898f). (editor, cb_Editor_dataChangedcxx . . $ MelderCallback#MelderCallback(fc624d2cd197112).); |
| 699 | if (! editor -> d_publicationCallbackcxx . . $ structEditor#d_publicationCallback.) |
| 700 | Editor_setPublicationCallbackcxx . . $ Editor_setPublicationCallback(ce9aea1332569354). (editor, cb_Editor_publicationcxx . . $ MelderCallback#MelderCallback(fc624d2cd197112).); |
| 701 | //Thing_setName (editor, Melder_cat (editor -> name.get(), U" [", ieditor + 1, U"]")); // would break existing scripts |
| 702 | return; |
| 703 | } |
| 704 | } |
| 705 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"(praat_installEditor:) Cannot have more than ", praat_MAXNUM_EDITORScxx . . $ `sys/praat.h:121:9`!, U" editors with one object."); |
| 706 | } |
| 707 | |
| 708 | void praat_installEditor2cxx . . $ praat_installEditor2(e9df3903f23ec0aa). (Editorcxx . . $ Editor# editor, integercxx . . $ integer# i1, integercxx . . $ integer# i2) { |
| 709 | if (! editor) |
| 710 | return; |
| 711 | integercxx . . $ integer# ieditor1 = 0; |
| 712 | for (; ieditor1 < praat_MAXNUM_EDITORScxx . . $ `sys/praat.h:121:9`!; ieditor1 ++) |
| 713 | if (! theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> listcxx . . $ structPraatObjects#list. [i1]. editorscxx . . $ structPraat_Object#editors. [ieditor1]) |
| 714 | break; |
| 715 | integercxx . . $ integer# ieditor2 = 0; |
| 716 | for (; ieditor2 < praat_MAXNUM_EDITORScxx . . $ `sys/praat.h:121:9`!; ieditor2 ++) |
| 717 | if (! theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> listcxx . . $ structPraatObjects#list. [i2]. editorscxx . . $ structPraat_Object#editors. [ieditor2]) |
| 718 | break; |
| 719 | if (ieditor1 < praat_MAXNUM_EDITORScxx . . $ `sys/praat.h:121:9`! && ieditor2 < praat_MAXNUM_EDITORScxx . . $ `sys/praat.h:121:9`!) { |
| 720 | theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> listcxx . . $ structPraatObjects#list. [i1]. editorscxx . . $ structPraat_Object#editors. [ieditor1] = theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> listcxx . . $ structPraatObjects#list. [i2]. editorscxx . . $ structPraat_Object#editors. [ieditor2] = editor; |
| 721 | Editor_setDestructionCallbackcxx . . $ Editor_setDestructionCallback(522aab46cb47898f). (editor, cb_Editor_destructioncxx . . $ MelderCallback#MelderCallback(fc624d2cd197112).); |
| 722 | Editor_setDataChangedCallbackcxx . . $ Editor_setDataChangedCallback(522aab46cb47898f). (editor, cb_Editor_dataChangedcxx . . $ MelderCallback#MelderCallback(fc624d2cd197112).); |
| 723 | if (! editor -> d_publicationCallbackcxx . . $ structEditor#d_publicationCallback.) |
| 724 | Editor_setPublicationCallbackcxx . . $ Editor_setPublicationCallback(ce9aea1332569354). (editor, cb_Editor_publicationcxx . . $ MelderCallback#MelderCallback(fc624d2cd197112).); |
| 725 | } else { |
| 726 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"(praat_installEditor2:) Cannot have more than ", praat_MAXNUM_EDITORScxx . . $ `sys/praat.h:121:9`!, U" editors with one object."); |
| 727 | } |
| 728 | } |
| 729 | |
| 730 | void praat_installEditor3cxx . . $ praat_installEditor3(ab2b30ea4ecbad1). (Editorcxx . . $ Editor# editor, integercxx . . $ integer# i1, integercxx . . $ integer# i2, integercxx . . $ integer# i3) { |
| 731 | if (! editor) |
| 732 | return; |
| 733 | integercxx . . $ integer# ieditor1 = 0; |
| 734 | for (; ieditor1 < praat_MAXNUM_EDITORScxx . . $ `sys/praat.h:121:9`!; ieditor1 ++) |
| 735 | if (! theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> listcxx . . $ structPraatObjects#list. [i1]. editorscxx . . $ structPraat_Object#editors. [ieditor1]) |
| 736 | break; |
| 737 | integercxx . . $ integer# ieditor2 = 0; |
| 738 | for (; ieditor2 < praat_MAXNUM_EDITORScxx . . $ `sys/praat.h:121:9`!; ieditor2 ++) |
| 739 | if (! theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> listcxx . . $ structPraatObjects#list. [i2]. editorscxx . . $ structPraat_Object#editors. [ieditor2]) |
| 740 | break; |
| 741 | integercxx . . $ integer# ieditor3 = 0; |
| 742 | for (; ieditor3 < praat_MAXNUM_EDITORScxx . . $ `sys/praat.h:121:9`!; ieditor3 ++) |
| 743 | if (! theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> listcxx . . $ structPraatObjects#list. [i3]. editorscxx . . $ structPraat_Object#editors. [ieditor3]) |
| 744 | break; |
| 745 | if (ieditor1 < praat_MAXNUM_EDITORScxx . . $ `sys/praat.h:121:9`! && ieditor2 < praat_MAXNUM_EDITORScxx . . $ `sys/praat.h:121:9`! && ieditor3 < praat_MAXNUM_EDITORScxx . . $ `sys/praat.h:121:9`!) { |
| 746 | theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> listcxx . . $ structPraatObjects#list. [i1]. editorscxx . . $ structPraat_Object#editors. [ieditor1] = theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> listcxx . . $ structPraatObjects#list. [i2]. editorscxx . . $ structPraat_Object#editors. [ieditor2] = theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> listcxx . . $ structPraatObjects#list. [i3]. editorscxx . . $ structPraat_Object#editors. [ieditor3] = editor; |
| 747 | Editor_setDestructionCallbackcxx . . $ Editor_setDestructionCallback(522aab46cb47898f). (editor, cb_Editor_destructioncxx . . $ MelderCallback#MelderCallback(fc624d2cd197112).); |
| 748 | Editor_setDataChangedCallbackcxx . . $ Editor_setDataChangedCallback(522aab46cb47898f). (editor, cb_Editor_dataChangedcxx . . $ MelderCallback#MelderCallback(fc624d2cd197112).); |
| 749 | if (! editor -> d_publicationCallbackcxx . . $ structEditor#d_publicationCallback.) |
| 750 | Editor_setPublicationCallbackcxx . . $ Editor_setPublicationCallback(ce9aea1332569354). (editor, cb_Editor_publicationcxx . . $ MelderCallback#MelderCallback(fc624d2cd197112).); |
| 751 | } else { |
| 752 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"(praat_installEditor3:) Cannot have more than ", praat_MAXNUM_EDITORScxx . . $ `sys/praat.h:121:9`!, U" editors with one object."); |
| 753 | } |
| 754 | } |
| 755 | |
| 756 | void praat_installEditorNcxx . . $ praat_installEditorN(517a323f6303e47). (Editorcxx . . $ Editor# editor, DaataListcxx . . $ DaataList# objects) { |
| 757 | if (! editor) |
| 758 | return; |
| 759 | /* |
| 760 | First check whether all objects in the DaataList are also in the List of Objects (Praat crashes if not), |
| 761 | and check whether there is room to add an editor for each. |
| 762 | */ |
| 763 | for (integercxx . . $ integer# iOrderedObject = 1; iOrderedObject <= objects->sizecxx . . $ CollectionOf#size.; iOrderedObject ++) { |
| 764 | Daatacxx . . $ Daata# object = objects->atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).iOrderedObject]; |
| 765 | integercxx . . $ integer# iPraatObject = 1; |
| 766 | for (; iPraatObject <= theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> ncxx . . $ structPraatObjects#n.; iPraatObject ++) { |
| 767 | if (object == theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> listcxx . . $ structPraatObjects#list. [iPraatObject]. objectcxx . . $ structPraat_Object#object.) { |
| 768 | int ieditor = 0; |
| 769 | for (; ieditor < praat_MAXNUM_EDITORScxx . . $ `sys/praat.h:121:9`!; ieditor ++) |
| 770 | if (! theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> listcxx . . $ structPraatObjects#list. [iPraatObject]. editorscxx . . $ structPraat_Object#editors. [ieditor]) |
| 771 | break; |
| 772 | if (ieditor >= praat_MAXNUM_EDITORScxx . . $ `sys/praat.h:121:9`!) |
| 773 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Cannot view the same object in more than ", praat_MAXNUM_EDITORScxx . . $ `sys/praat.h:121:9`!, U" windows."); |
| 774 | break; |
| 775 | } |
| 776 | } |
| 777 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (iPraatObject <= theCurrentPraatObjects -> n); // an element of the Ordered does not occur in the List of Objects |
| 778 | } |
| 779 | /* |
| 780 | There appears to be room for all elements of the DaataList. The editor window can appear. Install the editor in all objects. |
| 781 | */ |
| 782 | for (integercxx . . $ integer# iOrderedObject = 1; iOrderedObject <= objects->sizecxx . . $ CollectionOf#size.; iOrderedObject ++) { |
| 783 | Daatacxx . . $ Daata# object = objects->atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).iOrderedObject]; |
| 784 | integercxx . . $ integer# iPraatObject = 1; |
| 785 | for (; iPraatObject <= theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> ncxx . . $ structPraatObjects#n.; iPraatObject ++) { |
| 786 | if (object == theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> listcxx . . $ structPraatObjects#list. [iPraatObject]. objectcxx . . $ structPraat_Object#object.) { |
| 787 | int ieditor = 0; |
| 788 | for (; ieditor < praat_MAXNUM_EDITORScxx . . $ `sys/praat.h:121:9`!; ieditor ++) { |
| 789 | if (! theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> listcxx . . $ structPraatObjects#list. [iPraatObject]. editorscxx . . $ structPraat_Object#editors. [ieditor]) { |
| 790 | theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> listcxx . . $ structPraatObjects#list. [iPraatObject]. editorscxx . . $ structPraat_Object#editors. [ieditor] = editor; |
| 791 | Editor_setDestructionCallbackcxx . . $ Editor_setDestructionCallback(522aab46cb47898f). (editor, cb_Editor_destructioncxx . . $ MelderCallback#MelderCallback(fc624d2cd197112).); |
| 792 | Editor_setDataChangedCallbackcxx . . $ Editor_setDataChangedCallback(522aab46cb47898f). (editor, cb_Editor_dataChangedcxx . . $ MelderCallback#MelderCallback(fc624d2cd197112).); |
| 793 | if (! editor -> d_publicationCallbackcxx . . $ structEditor#d_publicationCallback.) |
| 794 | Editor_setPublicationCallbackcxx . . $ Editor_setPublicationCallback(ce9aea1332569354). (editor, cb_Editor_publicationcxx . . $ MelderCallback#MelderCallback(fc624d2cd197112).); |
| 795 | break; |
| 796 | } |
| 797 | } |
| 798 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (ieditor < praat_MAXNUM_EDITORScxx . . $ `sys/praat.h:121:9`!); // we just checked, but nevertheless |
| 799 | break; |
| 800 | } |
| 801 | } |
| 802 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (iPraatObject <= theCurrentPraatObjects -> n); // we already checked, but still |
| 803 | } |
| 804 | } |
| 805 | |
| 806 | void praat_dataChangedcxx . . $ praat_dataChanged(fde123624714e72). (Daatacxx . . $ Daata# object) { |
| 807 | /* |
| 808 | This function can be called at error time, which is weird. |
| 809 | */ |
| 810 | autostring32cxx . . $ autostring32# saveErrorcxx . . $ _autostring#_autostring(49f6e7a06ebc5aa8).; |
| 811 | const bool duringError = Melder_hasErrorcxx . . $ Melder_hasError(c9857a73d68e59ba). (); |
| 812 | if (duringError) { |
| 813 | if (Melder_hasCrashcxx . . $ Melder_hasCrash(c9857a73d68e59ba). ()) |
| 814 | return; // straight to the exit, without attempting to notify any editors of any data, which might well be corrupted |
| 815 | saveError =cxx . . $ _autostring#`operator=`(f562943cbc4bcf37). Melder_dup_fcxx . . $ Melder_dup_f(87bf156b1f548402). (Melder_getErrorcxx . . $ Melder_getError(1912f6684645c851). ()); |
| 816 | Melder_clearErrorcxx . . $ Melder_clearError(49f6e7a06ebc5aa8). (); |
| 817 | } |
| 818 | integercxx . . $ integer# IOBJECT; |
| 819 | WHEREcxx . . $ `sys/praat.h:198:9`! (OBJECTcxx . . $ `sys/praat.h:203:9`! == object) { |
| 820 | for (int ieditor = 0; ieditor < praat_MAXNUM_EDITORScxx . . $ `sys/praat.h:121:9`!; ieditor ++) { |
| 821 | Editorcxx . . $ Editor# editor = EDITORcxx . . $ `sys/praat.cpp:51:9`! [ieditor]; |
| 822 | if (editor) { |
| 823 | Editor_dataChangedcxx . . $ Editor_dataChanged(27010ae97811c311). (editor, nullptr); |
| 824 | if (duringError) |
| 825 | Melder_clearErrorcxx . . $ Melder_clearError(49f6e7a06ebc5aa8). (); // accept only the original error, and not the extra ones generated in the editors |
| 826 | } |
| 827 | } |
| 828 | } |
| 829 | if (duringError) { |
| 830 | Melder_appendError_noLinecxx . . $ Melder_appendError_noLine(afb30bc799649a62). (saveErrorcxx . . $ MelderArg#MelderArg(ff00d524ab0355ec)..getcxx . . $ _autostring#get(5a2a78a048fb49a8).()); // restore the original error message |
| 831 | /* |
| 832 | If we are during error time, then this error should be caught |
| 833 | either by `throw` (see praatM.h, two occurrences) or by Melder_flushError (also see praatM.h, one occurrence). |
| 834 | (last checked 2021-12-02) |
| 835 | */ |
| 836 | } |
| 837 | } |
| 838 | |
| 839 | static void helpProccxx . . $ helpProc(ff00d524ab0355ec). (conststring32cxx . . $ conststring32# query) { |
| 840 | if (theCurrentPraatApplicationcxx . . $ theCurrentPraatApplication. -> batchcxx . . $ structPraatApplication#batch.) { |
| 841 | Melder_flushErrorcxx . . $ Melder_flushError(6298c93241566110). (U"Cannot view manual from batch."); |
| 842 | return; |
| 843 | } |
| 844 | try { |
| 845 | autoManualcxx . . $ autoManual# manual = Manual_createcxx . . $ Manual_create(639647387c88cb04). (query, nullptr, theCurrentPraatApplicationcxx . . $ theCurrentPraatApplication. -> manPagescxx . . $ structPraatApplication#manPages., false, true); |
| 846 | manual.releaseToUsercxx . . $ autoSomeThing#releaseToUser(ced63f7c635d850d).(); |
| 847 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 848 | Melder_flushErrorcxx . . $ Melder_flushError(6298c93241566110). (U"help: no help on \"", query, U"\"."); |
| 849 | } |
| 850 | } |
| 851 | |
| 852 | static int publishProccxx . . $ publishProc(795020d01765d2fa). (autoDaatacxx . . $ autoDaata# me) { |
| 853 | try { |
| 854 | praat_newcxx . . $ praat_new(1e9b2ae553a98dd1). (mecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f)..movecxx . . $ autoSomeThing#move(25acc3554b7d1642).(), U""cxx . . $ MelderArg#MelderArg(ff00d524ab0355ec).); |
| 855 | praat_updateSelectioncxx . . $ praat_updateSelection(49f6e7a06ebc5aa8). (); |
| 856 | return 1; |
| 857 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 858 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Not published."); |
| 859 | } |
| 860 | } |
| 861 | |
| 862 | /***** QUIT *****/ |
| 863 | |
| 864 | FORMcxx . . $ `sys/praatM.h:79:9`! (DO_Quit, U"Confirm Quit", U"Quit") { |
| 865 | MUTABLE_COMMENTcxx . . $ `sys/praatM.h:140:9`! (label1, U"You have objects in your list!") |
| 866 | MUTABLE_COMMENTcxx . . $ `sys/praatM.h:140:9`! (label2, U"Do you still want to quit?") |
| 867 | OKcxx . . $ `sys/praatM.h:327:9`! |
| 868 | { |
| 869 | const bool youHaveObjectsInYourList = ( theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> ncxx . . $ structPraatObjects#n. > 0 ); |
| 870 | const bool youHaveUnsavedScriptsOrNotebooks = ( ScriptEditors_dirtycxx . . $ ScriptEditors_dirty(c9857a73d68e59ba). () || NotebookEditors_dirtycxx . . $ NotebookEditors_dirty(c9857a73d68e59ba). () ); |
| 871 | if (youHaveObjectsInYourList || youHaveUnsavedScriptsOrNotebooks) { |
| 872 | if (youHaveObjectsInYourList && youHaveUnsavedScriptsOrNotebooks) |
| 873 | SET_STRINGcxx . . $ `sys/praatM.h:344:9`! (label1, U"You have objects in your list, and unsaved scripts or notebooks!") |
| 874 | else if (youHaveUnsavedScriptsOrNotebooks) |
| 875 | SET_STRINGcxx . . $ `sys/praatM.h:344:9`! (label1, U"You have unsaved scripts or notebooks!") |
| 876 | else |
| 877 | SET_STRINGcxx . . $ `sys/praatM.h:344:9`! (label1, U"You have objects in your list!") |
| 878 | char32cxx . . $ char32# prompt [200]; |
| 879 | Melder_sprintcxx . . $ Melder_sprint(2b992b0fb5123bdf). (prompt,200, U"Do you still want to quit ", Melder_upperCaseAppNamecxx . . $ Melder_upperCaseAppName(1912f6684645c851).(), U"?"); |
| 880 | SET_STRINGcxx . . $ `sys/praatM.h:344:9`! (label2, prompt) |
| 881 | } else { |
| 882 | praat_exitcxx . . $ praat_exit(d4f767463ce0a6b3). (0); |
| 883 | } |
| 884 | } |
| 885 | DOcxx . . $ `sys/praatM.h:354:9`! |
| 886 | praat_exitcxx . . $ praat_exit(d4f767463ce0a6b3). (0); |
| 887 | END_NO_NEW_DATAcxx . . $ `sys/praatM.h:404:9`! |
| 888 | } |
| 889 | |
| 890 | static void cb_quitApplicationcxx . . $ cb_quitApplication(49f6e7a06ebc5aa8). () { |
| 891 | DO_Quitcxx . . $ DO_Quit(744a0abd3c8513c). (nullptr, 0, nullptr, nullptr, nullptr, nullptr, false, nullptr, nullptr); |
| 892 | } |
| 893 | |
| 894 | static void gui_cb_quitcxx . . $ gui_cb_quit(97cddd01752945f6). (Thingcxx . . $ Thing# /* me */) { |
| 895 | Gui_runQuitApplicationCallbackcxx . . $ Gui_runQuitApplicationCallback(49f6e7a06ebc5aa8). (); |
| 896 | } |
| 897 | |
| 898 | void praat_dontUsePictureWindowcxx . . $ praat_dontUsePictureWindow(49f6e7a06ebc5aa8). () { praatPcxx . . $ praatP..dontUsePictureWindowcxx . . $ PraatP#dontUsePictureWindow. = true; } |
| 899 | |
| 900 | /********** INITIALIZATION OF THE PRAAT SHELL **********/ |
| 901 | |
| 902 | #if defined (UNIXcxx . . $ `<built-in>:479:9`!) && ! defined (NO_GUI) |
| 903 | /* |
| 904 | sendpraat messages can only enter via SIGUSR1 at interrupt time. |
| 905 | We generate an event that should enter the main event loop at loop time. |
| 906 | */ |
| 907 | static void cb_sigusr1cxx . . $ cb_sigusr1(d4f767463ce0a6b3). (int signum) { |
| 908 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (signum == SIGUSR1cxx . . $ `<external>/1457673850468744829/signum-arch.h:49:9`!); |
| 909 | signal (SIGUSR1cxx . . $ `<external>/1457673850468744829/signum-arch.h:49:9`!, cb_sigusr1cxx . . $ cb_sigusr1(d4f767463ce0a6b3).); // keep this handler in the air |
| 910 | GdkEventProperty gevent; // or GdkEventSetting, once we can find its signal name |
| 911 | gevent. typecxx . . $ _GdkEventProperty#type. = GDK_PROPERTY_NOTIFY; // or GDK_SETTING |
| 912 | gevent. windowcxx . . $ _GdkEventProperty#window. = gtk_widget_get_window (GTK_WIDGETcxx . . $ `<external>/6031079988677191796/gtkwidget.h:58:9`! (theCurrentPraatApplication -> topShell -> d_gtkWindow)); |
| 913 | gevent. send_eventcxx . . $ _GdkEventProperty#send_event. = 1; |
| 914 | gevent. atomcxx . . $ _GdkEventProperty#atom. = gdk_atom_intern_static_string ("SENDPRAAT"); |
| 915 | gevent. timecxx . . $ _GdkEventProperty#time. = 0; |
| 916 | gevent. statecxx . . $ _GdkEventProperty#state. = GDK_PROPERTY_NEW_VALUE; |
| 917 | // Melder_casual (U"event put"); |
| 918 | gdk_event_put ((GdkEvent *) & gevent); // this is safe only if gdk_event_put is reentrant, which is unlikely because the event queue is global |
| 919 | } |
| 920 | #endif |
| 921 | |
| 922 | #if defined (UNIXcxx . . $ `<built-in>:479:9`!) |
| 923 | #if ! defined (NO_GUI) |
| 924 | static gboolean cb_userMessagecxx . . $ cb_userMessage(16416b5be8b8305a). (GtkWidget /* widget */, GdkEventProperty * /* event */, gpointer /* userData */) { |
| 925 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"client event called"); |
| 926 | autofilecxx . . $ autofile# fcxx . . $ autofile#autofile(49f6e7a06ebc5aa8).; |
| 927 | try { |
| 928 | f =cxx . . $ autofile#`operator=`(8d4262d45fc644ab). Melder_fopencxx . . $ Melder_fopen(feb98de266255aea). (& messageFilecxx . . $ messageFile., "r"); |
| 929 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 930 | Melder_clearErrorcxx . . $ Melder_clearError(49f6e7a06ebc5aa8). (); |
| 931 | return true; // OK |
| 932 | } |
| 933 | integercxx . . $ integer# pid = 0; |
| 934 | int narg = fscanf (f, "#%td", & pid); |
| 935 | f.closecxx . . $ autofile#close(1145552d769d7b5d). (& messageFilecxx . . $ messageFile.); |
| 936 | {// scope |
| 937 | autoPraatBackgroundcxx . . $ autoPraatBackground# backgroundcxx . . $ autoPraatBackground#autoPraatBackground(49f6e7a06ebc5aa8).; |
| 938 | try { |
| 939 | praat_executeScript_noGUIcxx . . $ praat_executeScript_noGUI(36849bf2e291e39f). (& messageFilecxx . . $ messageFile., true); // trust all messages, because they are sent by other apps that have control |
| 940 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 941 | Melder_flushErrorcxx . . $ Melder_flushError(6298c93241566110). (Melder_upperCaseAppNamecxx . . $ Melder_upperCaseAppName(1912f6684645c851).(), U": message not completely handled."); |
| 942 | } |
| 943 | } |
| 944 | if (narg != 0 && pid != 0) |
| 945 | kill (pid, SIGUSR2cxx . . $ `<external>/1457673850468744829/signum-arch.h:50:9`!); |
| 946 | return true; |
| 947 | } |
| 948 | #endif |
| 949 | #elif defined (_WIN32) |
| 950 | static int cb_userMessage () { |
| 951 | autoPraatBackground background; |
| 952 | try { |
| 953 | praat_executeScript_noGUI (& messageFile, true); // trust all messages, because they are sent by other apps that have control |
| 954 | } catch (MelderError) { |
| 955 | Melder_flushError (Melder_upperCaseAppName(), U": message not completely handled."); |
| 956 | } |
| 957 | return 0; |
| 958 | } |
| 959 | #if 0 |
| 960 | static void cb_openDocument (MelderFile file) { |
| 961 | char32 text [kMelder_MAXPATH+25]; |
| 962 | /* |
| 963 | The user dropped a file on the Praat icon, |
| 964 | or double-clicked a Praat file, |
| 965 | while Praat is already running. |
| 966 | */ |
| 967 | Melder_sprint (text,500, U"Read from file: ~", MelderFile_peekPath (file)); |
| 968 | sendpraat (nullptr, Melder_peek32to8 (Melder_upperCaseAppName()), 0, Melder_peek32to8 (text)); |
| 969 | } |
| 970 | static void cb_finishedOpeningDocuments () { |
| 971 | praat_updateSelection (); |
| 972 | } |
| 973 | #endif |
| 974 | #elif macintosh |
| 975 | static int (*theUserMessageCallback) (); |
| 976 | static void mac_setUserMessageCallback (int (*userMessageCallback) ()) { |
| 977 | theUserMessageCallback = userMessageCallback; |
| 978 | } |
| 979 | static pascal OSErr mac_processSignal8 (const AppleEvent *theAppleEvent, AppleEvent * /* reply */, long /* handlerRefCon */) { |
| 980 | static bool duringAppleEvent = false; // FIXME: may have to be atomic? |
| 981 | if (! duringAppleEvent) { |
| 982 | //char *buffer; |
| 983 | //Size actualSize; |
| 984 | duringAppleEvent = true; |
| 985 | ProcessSerialNumber psn; |
| 986 | GetCurrentProcess (& psn); |
| 987 | SetFrontProcess (& psn); |
| 988 | //AEGetParamPtr (theAppleEvent, 1, typeUTF8Text, nullptr, nullptr, 0, & actualSize); |
| 989 | //buffer = (char *) malloc ((size_t) actualSize); |
| 990 | //AEGetParamPtr (theAppleEvent, 1, typeUTF8Text, nullptr, & buffer [0], actualSize, nullptr); |
| 991 | if (theUserMessageCallback) { |
| 992 | //autostring32 buffer32 = Melder_8to32_e (buffer); |
| 993 | //theUserMessageCallback (buffer32.get()); |
| 994 | theUserMessageCallback (); |
| 995 | } |
| 996 | //free (buffer); |
| 997 | duringAppleEvent = false; |
| 998 | } |
| 999 | return noErr; |
| 1000 | } |
| 1001 | static int cb_userMessage () { |
| 1002 | autoPraatBackground background; |
| 1003 | try { |
| 1004 | //praat_executeScriptFromText (message); |
| 1005 | praat_executeScript_noGUI (& messageFile, true); // trust all messages, because they are sent by other apps that have control |
| 1006 | } catch (MelderError) { |
| 1007 | Melder_flushError (Melder_upperCaseAppName(), U": message not completely handled."); |
| 1008 | } |
| 1009 | return 0; |
| 1010 | } |
| 1011 | #endif |
| 1012 | |
| 1013 | static conststring32cxx . . $ conststring32# thePraatStandAloneScriptTextcxx . . $ thePraatStandAloneScriptText. = nullptr; |
| 1014 | |
| 1015 | void praat_setStandAloneScriptTextcxx . . $ praat_setStandAloneScriptText(ff00d524ab0355ec). (conststring32cxx . . $ conststring32# text) { |
| 1016 | thePraatStandAloneScriptTextcxx . . $ thePraatStandAloneScriptText. = text; |
| 1017 | } |
| 1018 | |
| 1019 | static bool tryToAttachToTheCommandLinecxx . . $ tryToAttachToTheCommandLine(c9857a73d68e59ba). () |
| 1020 | { |
| 1021 | bool weHaveSucceeded = false; |
| 1022 | #if defined (_WIN32) |
| 1023 | /* |
| 1024 | * On Windows, console applications are automatically attached to the command line, |
| 1025 | * but Praat is always a Windows application instead, so command line attachment |
| 1026 | * has to be handled explicitly, as here. |
| 1027 | */ |
| 1028 | if (AttachConsole (ATTACH_PARENT_PROCESS)) { // was Praat called from either a console window or a "system" command? |
| 1029 | weHaveSucceeded = true; |
| 1030 | } |
| 1031 | #else |
| 1032 | weHaveSucceeded = isatty (fileno (stdincxx . . $ `<external>/232824719582829767/stdio.h:153:9`!)) || isatty (fileno (stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!)) || isatty (fileno (stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!)); |
| 1033 | /* |
| 1034 | The result is `true` if Praat was called from a terminal window or some system() commands or Xcode, |
| 1035 | and `false` if Praat was called from the Finder by double-clicking or dropping a file. |
| 1036 | |
| 1037 | This might be incorrectly false only if all three streams are redirected to a file or pipe, |
| 1038 | but this hasn't been tested yet. |
| 1039 | */ |
| 1040 | #endif |
| 1041 | return weHaveSucceeded; |
| 1042 | } |
| 1043 | |
| 1044 | static void setThePraatLocalecxx . . $ setThePraatLocale(49f6e7a06ebc5aa8). () { |
| 1045 | /* |
| 1046 | We use only the "C" locale, because iswalpha works differently |
| 1047 | on different platforms, even if UTF-8 is specified (e.g. try 0x0905, |
| 1048 | which is an `alpha` on Windows but not on Mac and Linux). |
| 1049 | We do have to replace everything from <wctype.h>: |
| 1050 | - all iswalpha by iswalpha_portable |
| 1051 | - all iswalnum by iswalnum_portable |
| 1052 | - all iswpunct by iswpunct_portable |
| 1053 | - all iswspace by iswspace_portable |
| 1054 | - all iswdigit by iswdigit_portable |
| 1055 | - all iswlower by iswlower_portable |
| 1056 | - all iswupper by iswupper_portable |
| 1057 | */ |
| 1058 | setlocale (LC_ALLcxx . . $ `<external>/3736975272097309885/locale.h:41:9`!, "C"); // said to be superfluous on Windows, but cannot hurt |
| 1059 | } |
| 1060 | |
| 1061 | static void installPraatShellPreferencescxx . . $ installPraatShellPreferences(49f6e7a06ebc5aa8). () { |
| 1062 | praat_statistics_prefscxx . . $ praat_statistics_prefs(49f6e7a06ebc5aa8). (); // number of sessions, memory used... |
| 1063 | praat_picture_prefscxx . . $ praat_picture_prefs(49f6e7a06ebc5aa8). (); // font... |
| 1064 | Graphics_prefscxx . . $ Graphics_prefs(49f6e7a06ebc5aa8). (); |
| 1065 | Ui_prefscxx . . $ Ui_prefs(49f6e7a06ebc5aa8). (); |
| 1066 | structDataGuicxx . . $ structDataGui# :: f_preferencescxx . . $ structDataGui#f_preferences(49f6e7a06ebc5aa8). (); // erase picture first... |
| 1067 | structEditorcxx . . $ structEditor# :: f_preferencescxx . . $ structEditor#f_preferences(49f6e7a06ebc5aa8). (); // shell size... |
| 1068 | structHyperPagecxx . . $ structHyperPage# :: f_preferencescxx . . $ structHyperPage#f_preferences(49f6e7a06ebc5aa8). (); // font... |
| 1069 | Site_prefscxx . . $ Site_prefs(49f6e7a06ebc5aa8). (); // print command... |
| 1070 | Melder_audio_prefscxx . . $ Melder_audio_prefs(49f6e7a06ebc5aa8). (); // asynchronicity, silence after... |
| 1071 | Melder_textEncoding_prefscxx . . $ Melder_textEncoding_prefs(49f6e7a06ebc5aa8). (); |
| 1072 | Printer_prefscxx . . $ Printer_prefs(49f6e7a06ebc5aa8). (); // paper size, printer command... |
| 1073 | structTextEditorcxx . . $ structTextEditor# :: f_preferencescxx . . $ structTextEditor#f_preferences(49f6e7a06ebc5aa8). (); // font size... |
| 1074 | } |
| 1075 | |
| 1076 | extern "C" void praatlib_init () { |
| 1077 | setThePraatLocalecxx . . $ setThePraatLocale(49f6e7a06ebc5aa8). (); // FIXME: don't use the global locale |
| 1078 | Melder_initcxx . . $ Melder_init(49f6e7a06ebc5aa8). (); |
| 1079 | Melder_rememberShellDirectorycxx . . $ Melder_rememberShellDirectory(49f6e7a06ebc5aa8). (); |
| 1080 | installPraatShellPreferencescxx . . $ installPraatShellPreferences(49f6e7a06ebc5aa8). (); // needed in the library, because this sets the defaults |
| 1081 | praatPcxx . . $ praatP..argccxx . . $ PraatP#argc. = 0; |
| 1082 | praatPcxx . . $ praatP..argvcxx . . $ PraatP#argv. = nullptr; |
| 1083 | praatPcxx . . $ praatP..argumentNumbercxx . . $ PraatP#argumentNumber. = 1; |
| 1084 | Melder_batchcxx . . $ Melder_batch. = true; |
| 1085 | praatPcxx . . $ praatP..userWantsToOpencxx . . $ PraatP#userWantsToOpen. = false; |
| 1086 | Melder_setAppNamecxx . . $ Melder_setAppName(ff00d524ab0355ec). (U"Praatlib"); |
| 1087 | theCurrentPraatApplicationcxx . . $ theCurrentPraatApplication. -> batchcxx . . $ structPraatApplication#batch. = true; |
| 1088 | Melder_getHomeDircxx . . $ Melder_getHomeDir(63f38d3b6b86d1dc). (& homeDircxx . . $ homeDir.); |
| 1089 | Thing_recognizeClassesByNamecxx . . $ Thing_recognizeClassesByName(f327490b5edb0dcb). (classCollectioncxx . . $ classCollection., classStringscxx . . $ classStrings., classManPagescxx . . $ classManPages., classStringSetcxx . . $ classStringSet.); |
| 1090 | Thing_recognizeClassByOtherNamecxx . . $ Thing_recognizeClassByOtherName(cb82456e35792de1). (classStringSetcxx . . $ classStringSet., U"SortedSetOfString"); |
| 1091 | Melder_backgroundingcxx . . $ Melder_backgrounding. = true; |
| 1092 | praat_addMenuscxx . . $ praat_addMenus(20efc9fbfef198b1). (nullptr); |
| 1093 | praat_addFixedButtonscxx . . $ praat_addFixedButtons(20efc9fbfef198b1). (nullptr); |
| 1094 | praat_addMenus2cxx . . $ praat_addMenus2(49f6e7a06ebc5aa8). (); |
| 1095 | } |
| 1096 | |
| 1097 | static void injectMessageAndInformationProcscxx . . $ injectMessageAndInformationProcs(20efc9fbfef198b1). (GuiWindowcxx . . $ GuiWindow# parent) { |
| 1098 | Gui_injectMessageProcscxx . . $ Gui_injectMessageProcs(20efc9fbfef198b1). (parent); |
| 1099 | InfoEditor_injectInformationProccxx . . $ InfoEditor_injectInformationProc(49f6e7a06ebc5aa8). (); |
| 1100 | } |
| 1101 | |
| 1102 | static void printHelpcxx . . $ printHelp(49f6e7a06ebc5aa8). () { |
| 1103 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"Usage:"); |
| 1104 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U" To start up Praat with a new GUI:"); |
| 1105 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U" praat [OPTION]..."); |
| 1106 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U""); |
| 1107 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U" To run a Praat script without a GUI:"); |
| 1108 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U" praat [--run] [OPTION]... SCRIPT-FILE-NAME [SCRIPT-ARGUMENT]..."); |
| 1109 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U" The switch --run is superfluous when you use a Console or Terminal"); |
| 1110 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U" interactively, but necessary if you call Praat programmatically."); |
| 1111 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U""); |
| 1112 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U" To open one or more files, preferably in an existing GUI instance of Praat:"); |
| 1113 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U" praat --open [OPTION]... FILE-NAME..."); |
| 1114 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U" Data files will open in the Objects window, script files in a script window."); |
| 1115 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U""); |
| 1116 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U" To open one or more files in a new GUI instance of Praat:"); |
| 1117 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U" praat --new-open [OPTION]... FILE-NAME..."); |
| 1118 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U""); |
| 1119 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U" To run a Praat script in a preferably existing GUI instance of Praat:"); |
| 1120 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U" praat --send [OPTION]... SCRIPT-FILE-NAME [SCRIPT-ARGUMENT]..."); |
| 1121 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U""); |
| 1122 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U" To run a Praat script in a new GUI instance of Praat:"); |
| 1123 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U" praat --new-send [OPTION]... SCRIPT-FILE-NAME [SCRIPT-ARGUMENT]..."); |
| 1124 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U""); |
| 1125 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U" As --send, but potentially presenting a form to query for arguments:"); |
| 1126 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U" praat --send-or-form [OPTION]... SCRIPT-FILE-NAME"); |
| 1127 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U""); |
| 1128 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U" As --new-send, but potentially presenting a form to query for arguments:"); |
| 1129 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U" praat --new-send-or-form [OPTION]... SCRIPT-FILE-NAME"); |
| 1130 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U""); |
| 1131 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U" To start up Praat in an interactive command line session:"); |
| 1132 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U" praat [OPTION]... -"); |
| 1133 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U""); |
| 1134 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U" To print the Praat version:"); |
| 1135 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U" praat --version"); |
| 1136 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U""); |
| 1137 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U" To print this list of command line options:"); |
| 1138 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U" praat --help"); |
| 1139 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U""); |
| 1140 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"Options:"); |
| 1141 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U" --FULL-TRUST allow this script to save files and run system commands"); |
| 1142 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U" --no-pref-files don't read or write the preferences file and the buttons file"); |
| 1143 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U" --no-plugins don't activate the plugins"); |
| 1144 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U" --pref-dir=<DIR> set the preferences folder to <DIR>"); |
| 1145 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U" -u, --utf16 use UTF-16LE output encoding, no BOM (the default on Windows)"); |
| 1146 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U" -8, --utf8 use UTF-8 output encoding (the default on MacOS and Linux)"); |
| 1147 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U" -a, --ansi use ISO Latin-1 output encoding (lossy, hence not recommended)"); |
| 1148 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U" (on Windows, use -8 or -a when you redirect to a pipe or file)"); |
| 1149 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U" --trace switch tracing on at start-up (see Praat > Technical > Debug)"); |
| 1150 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U" --hide-picture hide the Picture window at start-up"); |
| 1151 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U" --debug=58 set the Debug option to e.g. 58 at start-up"); |
| 1152 | } |
| 1153 | |
| 1154 | #ifdef _WIN32 |
| 1155 | static void *theWinApplicationWindow; |
| 1156 | #endif |
| 1157 | |
| 1158 | static bool tryToSwitchToRunningPraatcxx . . $ tryToSwitchToRunningPraat(c7f7a522d592f53e). (bool foundTheOpenOption, bool foundTheSendOption, bool foundTheSendOrFormOption) { |
| 1159 | /* |
| 1160 | This function returns true only if we can be certain that we have sent |
| 1161 | the command line to an already running invocation of Praat that is not identical to ourselves |
| 1162 | (though its Praat version has to be identical to ours). |
| 1163 | If there are doubts anywhere, then we just return false, |
| 1164 | because having zero instances of Praat is worse than having two. |
| 1165 | */ |
| 1166 | const integercxx . . $ integer# pidOfCurrentPraat = getpid (); |
| 1167 | if (pidOfCurrentPraat == 0) { |
| 1168 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"We have no PID, so we will not be able to check that we are different from any running Praat."); |
| 1169 | return false; |
| 1170 | } |
| 1171 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"Process ID of current Praat: ", pidOfCurrentPraat); |
| 1172 | /* |
| 1173 | Figure out the Process ID of an already running instance of Praat. |
| 1174 | */ |
| 1175 | integercxx . . $ integer# pidOfRunningPraat = 0; // mutable, to be filled in from file |
| 1176 | #if defined (macintosh) |
| 1177 | /* |
| 1178 | We have to implement this differently from how sendpraat implements this, |
| 1179 | because sendpraat just sends its message to a program with application signature 'PpgB', |
| 1180 | which by default is the current (starting-up) Praat rather than the already running Praat. |
| 1181 | These two instances of Praat can be distinguished by their Process ID. |
| 1182 | We look up the Process ID of the running Praat in a list associated with the running program's Bundle ID. |
| 1183 | */ |
| 1184 | NSRunningApplication *currentPraat = [NSRunningApplication currentApplication]; |
| 1185 | NSString *currentBundleIdentifier = [currentPraat bundleIdentifier]; // for instance @"org.praat.Praat" |
| 1186 | trace (U"Current bundle identifier: ", Melder_peek8to32_u ([currentBundleIdentifier UTF8String])); |
| 1187 | NSArray<NSRunningApplication *> *list = [NSRunningApplication runningApplicationsWithBundleIdentifier: currentBundleIdentifier]; |
| 1188 | NSRunningApplication *runningPraat = nullptr; |
| 1189 | const integer numberOfPraats = uinteger_to_integer_a ([list count]); |
| 1190 | for (integer ipraat = 1; ipraat <= numberOfPraats; ipraat ++) { |
| 1191 | NSRunningApplication *praat = [list objectAtIndex: ipraat-1]; |
| 1192 | pid_t pidOfPraat = [praat processIdentifier]; |
| 1193 | trace (U"Process ID ", pidOfPraat); |
| 1194 | if (pidOfPraat != pidOfCurrentPraat) { |
| 1195 | runningPraat = praat; |
| 1196 | pidOfRunningPraat = pidOfPraat; |
| 1197 | } |
| 1198 | } |
| 1199 | if (pidOfRunningPraat == 0) { |
| 1200 | trace (U"There seem to be no other running instances of Praat."); |
| 1201 | return false; |
| 1202 | } |
| 1203 | #elif defined (_WIN32) |
| 1204 | HWND winWindow = HWND (theWinApplicationWindow); |
| 1205 | if (! winWindow) |
| 1206 | return false; |
| 1207 | #elif defined (UNIXcxx . . $ `<built-in>:479:9`!) |
| 1208 | integercxx . . $ integer# versionOfRunningPraat = 0; // mutable, to be filled in from file |
| 1209 | try { |
| 1210 | autofilecxx . . $ autofile# f = Melder_fopencxx . . $ autofile#autofile(8d4262d45fc644ab). (& pidFilecxx . . $ pidFile., "r"); |
| 1211 | int numberOfRead = fscanf (f, "%td %td", & pidOfRunningPraat, & versionOfRunningPraat); |
| 1212 | if (numberOfRead < 1) { |
| 1213 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"No PID in PID file, " |
| 1214 | "so we will not be able to check that Praat is already running."); |
| 1215 | return false; |
| 1216 | } |
| 1217 | if (numberOfRead < 2) { |
| 1218 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"No Praat version number in PID file, " |
| 1219 | "so we will not be able to check that the same version of Praat is already running."); |
| 1220 | return false; |
| 1221 | } |
| 1222 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 1223 | Melder_clearErrorcxx . . $ Melder_clearError(49f6e7a06ebc5aa8). (); // it is not an error if the PID file does not exist or is broken |
| 1224 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"PID file does not exist, " |
| 1225 | "so Praat is probably not running yet. We are process ", pidOfCurrentPraat, U"."); |
| 1226 | return false; |
| 1227 | } |
| 1228 | const integercxx . . $ integer# versionOfCurrentPraat = Melder_appVersioncxx . . $ Melder_appVersion(da6335ded91d79c2).(); |
| 1229 | if (versionOfRunningPraat != versionOfCurrentPraat) { |
| 1230 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"The current version of Praat differs from the version of the Praat that may already be running, " |
| 1231 | "so we cannot be sure it would respond as we would."); |
| 1232 | return false; |
| 1233 | } |
| 1234 | if (pidOfRunningPraat == pidOfCurrentPraat) { |
| 1235 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"Very rare condition: a Praat that crashed had the same PID as we have (in an earlier computer session), " |
| 1236 | "so Praat is probably not running yet."); |
| 1237 | return false; |
| 1238 | } |
| 1239 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"An instance with PID ", pidOfRunningPraat, U" is still running."); |
| 1240 | #endif |
| 1241 | /* |
| 1242 | Bring the running Praat to the foreground. |
| 1243 | */ |
| 1244 | Melder_casualcxx . . $ Melder_casual(6298c93241566110). (U"An instance of Praat that is not me is already running."); |
| 1245 | #if defined (macintosh) |
| 1246 | int activationVersion = 1; // 1 or 2 |
| 1247 | if (activationVersion == 1) { // deprecated since OS X 10.9, but it works, unlike the alternative |
| 1248 | ProcessSerialNumber psnOfRunningPraat; |
| 1249 | GetProcessForPID (pidOfRunningPraat, & psnOfRunningPraat); |
| 1250 | SetFrontProcess (& psnOfRunningPraat); // this works |
| 1251 | } else if (activationVersion == 2) { |
| 1252 | const bool activated = [runningPraat |
| 1253 | activateWithOptions: |
| 1254 | NSApplicationActivateAllWindows | // this option seems to be refused (if you take it alone, `activated` will be false) |
| 1255 | NSApplicationActivateIgnoringOtherApps // (is the activation policy right?) |
| 1256 | ]; |
| 1257 | Melder_casual (U"activated: ", activated); |
| 1258 | } |
| 1259 | #elif defined (_WIN32) |
| 1260 | if (IsIconic (winWindow)) |
| 1261 | ShowWindow (winWindow, SW_RESTORE); |
| 1262 | SetForegroundWindow (winWindow); |
| 1263 | #elif defined (UNIXcxx . . $ `<built-in>:479:9`!) |
| 1264 | /* |
| 1265 | TODO: bring Praat to the foreground on GTK. |
| 1266 | */ |
| 1267 | #endif |
| 1268 | if (! foundTheOpenOption && ! foundTheSendOption && ! foundTheSendOrFormOption) |
| 1269 | return true; |
| 1270 | /* |
| 1271 | Send something to the running Praat, and bail out. |
| 1272 | */ |
| 1273 | autoMelderStringcxx . . $ autoMelderString# text32cxx . . $ autoMelderString#autoMelderString(49f6e7a06ebc5aa8).; |
| 1274 | if (foundTheOpenOption) { |
| 1275 | /* |
| 1276 | praat --open [OPTION]... FILE-NAME... |
| 1277 | */ |
| 1278 | for (integercxx . . $ integer# iarg = praatPcxx . . $ praatP..argumentNumbercxx . . $ PraatP#argumentNumber.; iarg < praatPcxx . . $ praatP..argccxx . . $ PraatP#argc.; iarg ++) { // do not change praatP.argumentNumber itself (we might return false) |
| 1279 | TRACEcxx . . $ `melder/melder_debug.h:54:9`! |
| 1280 | structMelderFilecxx . . $ structMelderFile# file { }; |
| 1281 | Melder_relativePathToFilecxx . . $ Melder_relativePathToFile(82691f2ee21fbb13). (Melder_peek8to32_u (praatPcxx . . $ praatP..argvcxx . . $ PraatP#argv. [iarg]), & file); |
| 1282 | conststring32cxx . . $ conststring32# absolutePath = MelderFile_peekPathcxx . . $ MelderFile_peekPath(d9f043369fa9b55b). (& file); |
| 1283 | MelderString_appendcxx . . $ MelderString_append(65be51a793e0ff96). (& text32, U"Read from file: ~", absolutePath, U"\n"); |
| 1284 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"Argument ", iarg, U": will open path ", absolutePath); |
| 1285 | } // TODO: we could send an openDocuments message instead |
| 1286 | } else if (foundTheSendOption) { |
| 1287 | /* |
| 1288 | praat --send [OPTION]... SCRIPT-FILE-NAME [SCRIPT-ARGUMENT]... |
| 1289 | */ |
| 1290 | MelderString_appendcxx . . $ MelderString_append(65be51a793e0ff96). (& text32, U"setWorkingDirectory: "); |
| 1291 | structMelderFoldercxx . . $ structMelderFolder# currentFolder { }; |
| 1292 | Melder_getCurrentFoldercxx . . $ Melder_getCurrentFolder(63f38d3b6b86d1dc). (& currentFolder); |
| 1293 | MelderString_appendcxx . . $ MelderString_append(65be51a793e0ff96). (& text32, quote_doubleSTRcxx . . $ quote_doubleSTR(87bf156b1f548402). (MelderFolder_peekPathcxx . . $ MelderFolder_peekPath(fbe3b4f4d15c56ee). (& currentFolder)).getcxx . . $ _autostring#get(5a2a78a048fb49a8).()); |
| 1294 | MelderString_appendcxx . . $ MelderString_append(65be51a793e0ff96). (& text32, U"\nrunScript: "); |
| 1295 | structMelderFilecxx . . $ structMelderFile# scriptFile { }; |
| 1296 | Melder_relativePathToFilecxx . . $ Melder_relativePathToFile(82691f2ee21fbb13). (theCurrentPraatApplicationcxx . . $ theCurrentPraatApplication. -> batchNamecxx . . $ structPraatApplication#batchName..stringcxx . . $ MelderString#string., & scriptFile); |
| 1297 | conststring32cxx . . $ conststring32# absolutePath = MelderFile_peekPathcxx . . $ MelderFile_peekPath(d9f043369fa9b55b). (& scriptFile); |
| 1298 | MelderString_appendcxx . . $ MelderString_append(65be51a793e0ff96). (& text32, quote_doubleSTRcxx . . $ quote_doubleSTR(87bf156b1f548402). (absolutePath).getcxx . . $ _autostring#get(5a2a78a048fb49a8).()); |
| 1299 | //TRACE |
| 1300 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"--send ", absolutePath); |
| 1301 | for (integercxx . . $ integer# iarg = praatPcxx . . $ praatP..argumentNumbercxx . . $ PraatP#argumentNumber.; iarg < praatPcxx . . $ praatP..argccxx . . $ PraatP#argc.; iarg ++) // do not change praatP.argumentNumber itself (we might return false) |
| 1302 | MelderString_appendcxx . . $ MelderString_append(65be51a793e0ff96). (& text32, U", ", quote_doubleSTRcxx . . $ quote_doubleSTR(87bf156b1f548402). (Melder_peek8to32_u (praatPcxx . . $ praatP..argvcxx . . $ PraatP#argv. [iarg])).getcxx . . $ _autostring#get(5a2a78a048fb49a8).()); |
| 1303 | } else if (foundTheSendOrFormOption) { |
| 1304 | /* |
| 1305 | praat --send-or-form [OPTION]... SCRIPT-FILE-NAME |
| 1306 | */ |
| 1307 | MelderString_appendcxx . . $ MelderString_append(65be51a793e0ff96). (& text32, U"setWorkingDirectory: "); |
| 1308 | structMelderFoldercxx . . $ structMelderFolder# currentFolder { }; |
| 1309 | Melder_getCurrentFoldercxx . . $ Melder_getCurrentFolder(63f38d3b6b86d1dc). (& currentFolder); |
| 1310 | MelderString_appendcxx . . $ MelderString_append(65be51a793e0ff96). (& text32, quote_doubleSTRcxx . . $ quote_doubleSTR(87bf156b1f548402). (MelderFolder_peekPathcxx . . $ MelderFolder_peekPath(fbe3b4f4d15c56ee). (& currentFolder)).getcxx . . $ _autostring#get(5a2a78a048fb49a8).()); |
| 1311 | MelderString_appendcxx . . $ MelderString_append(65be51a793e0ff96). (& text32, U"\nrunScriptWithForm: "); |
| 1312 | structMelderFilecxx . . $ structMelderFile# scriptFile { }; |
| 1313 | Melder_relativePathToFilecxx . . $ Melder_relativePathToFile(82691f2ee21fbb13). (theCurrentPraatApplicationcxx . . $ theCurrentPraatApplication. -> batchNamecxx . . $ structPraatApplication#batchName..stringcxx . . $ MelderString#string., & scriptFile); |
| 1314 | conststring32cxx . . $ conststring32# absolutePath = MelderFile_peekPathcxx . . $ MelderFile_peekPath(d9f043369fa9b55b). (& scriptFile); |
| 1315 | MelderString_appendcxx . . $ MelderString_append(65be51a793e0ff96). (& text32, quote_doubleSTRcxx . . $ quote_doubleSTR(87bf156b1f548402). (absolutePath).getcxx . . $ _autostring#get(5a2a78a048fb49a8).()); |
| 1316 | //TRACE |
| 1317 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"--send-or-form ", absolutePath); |
| 1318 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (praatP.argc - praatP.argumentNumber == 0, |
| 1319 | U"The --send-or-form switch should be followed by precisely one argument, namely the name of the script file."); |
| 1320 | } |
| 1321 | autostring8cxx . . $ autostring8# text8 = Melder_32to8cxx . . $ Melder_32to8(d0484fb546b1094e). (text32.stringcxx . . $ MelderString#string.); |
| 1322 | #if defined (macintosh) |
| 1323 | autofile f; |
| 1324 | try { |
| 1325 | f = Melder_fopen (& messageFile, "w"); |
| 1326 | if (praatP. fullTrust) |
| 1327 | fprintf (f, "\n# --FULL-TRUST\n"); |
| 1328 | fprintf (f, "%s", text8.get()); |
| 1329 | f.close (& messageFile); |
| 1330 | } catch (MelderError) { |
| 1331 | Melder_clearError (); |
| 1332 | Melder_casual (U"Cannot write message file \"", MelderFile_messageName (& messageFile), |
| 1333 | U"\" (no privilege to write to folder, or disk full)."); |
| 1334 | return false; |
| 1335 | } |
| 1336 | |
| 1337 | |
| 1338 | const int timeOut = 0; |
| 1339 | AESendMode aeOptions = ( timeOut == 0 ? kAENoReply : kAEWaitReply ) | kAECanInteract | kAECanSwitchLayer; |
| 1340 | int appleEventVersion = 2; // 1, 2 or 3 |
| 1341 | if (appleEventVersion == 1) { |
| 1342 | ProcessSerialNumber psnOfRunningPraat; |
| 1343 | GetProcessForPID (pidOfRunningPraat, & psnOfRunningPraat); |
| 1344 | AppleEvent psnProgramDescriptor = { typeNull, nullptr }; |
| 1345 | OSErr err = AECreateDesc (typeProcessSerialNumber, & psnOfRunningPraat, sizeof (psnOfRunningPraat), & psnProgramDescriptor); |
| 1346 | if (err != noErr) |
| 1347 | return false; |
| 1348 | AppleEvent appleEvent; |
| 1349 | err = AECreateAppleEvent (758934755, 0, & psnProgramDescriptor, kAutoGenerateReturnID, 1, & appleEvent); |
| 1350 | if (err != noErr) { |
| 1351 | AEDisposeDesc (& psnProgramDescriptor); |
| 1352 | return false; |
| 1353 | } |
| 1354 | err = AEPutParamPtr (& appleEvent, 1, typeChar, text8.get(), (Size) strlen (text8.get()) + 1); |
| 1355 | if (err != noErr) { |
| 1356 | AEDisposeDesc (& appleEvent); |
| 1357 | AEDisposeDesc (& psnProgramDescriptor); |
| 1358 | return false; |
| 1359 | } |
| 1360 | AppleEvent reply; |
| 1361 | OSStatus status = AESendMessage (& appleEvent, & reply, aeOptions, timeOut == 0 ? kNoTimeOut : 60 * timeOut); |
| 1362 | if (status != 0) { |
| 1363 | AEDisposeDesc (& appleEvent); |
| 1364 | AEDisposeDesc (& psnProgramDescriptor); |
| 1365 | return false; // event not sent correctly |
| 1366 | } |
| 1367 | return true; // we did send an event to a running non-identical Praat successfully |
| 1368 | } else if (appleEventVersion == 2) { |
| 1369 | pid_t pidOfRunningPraat_pidt = pid_t (pidOfRunningPraat); |
| 1370 | NSAppleEventDescriptor *pidProgramDescriptor = [NSAppleEventDescriptor |
| 1371 | descriptorWithDescriptorType: typeKernelProcessID bytes: & pidOfRunningPraat_pidt length: sizeof (pid_t)]; |
| 1372 | if (! pidProgramDescriptor) |
| 1373 | return false; |
| 1374 | AppleEvent appleEvent; |
| 1375 | OSErr err = AECreateAppleEvent (758934755, 0, [pidProgramDescriptor aeDesc], kAutoGenerateReturnID, 1, & appleEvent); |
| 1376 | if (err != noErr) { |
| 1377 | // pidProgramDescriptor is autoreleased |
| 1378 | return false; |
| 1379 | } |
| 1380 | err = AEPutParamPtr (& appleEvent, 1, typeChar, text8.get(), (Size) strlen (text8.get()) + 1); |
| 1381 | if (err != noErr) { |
| 1382 | AEDisposeDesc (& appleEvent); |
| 1383 | // pidProgramDescriptor is autoreleased |
| 1384 | return false; |
| 1385 | } |
| 1386 | AppleEvent reply; |
| 1387 | OSStatus status = AESendMessage (& appleEvent, & reply, aeOptions, timeOut == 0 ? kNoTimeOut : 60 * timeOut); |
| 1388 | if (status != 0) { |
| 1389 | AEDisposeDesc (& appleEvent); |
| 1390 | // pidProgramDescriptor is autoreleased |
| 1391 | return false; // event not sent correctly |
| 1392 | } |
| 1393 | TRACE |
| 1394 | trace (U"event sent successfully"); |
| 1395 | return true; // we did send an event to a running non-identical Praat successfully |
| 1396 | } else if (appleEventVersion == 3) { // from 10.11 on |
| 1397 | NSAppleEventDescriptor *pidProgramDescriptor = [NSAppleEventDescriptor |
| 1398 | descriptorWithProcessIdentifier: pidOfRunningPraat]; |
| 1399 | if (! pidProgramDescriptor) |
| 1400 | return false; |
| 1401 | NSAppleEventDescriptor *appleEvent = [NSAppleEventDescriptor |
| 1402 | appleEventWithEventClass: 758934755 eventID: 0 targetDescriptor: pidProgramDescriptor |
| 1403 | returnID: kAutoGenerateReturnID transactionID: 1 |
| 1404 | ]; |
| 1405 | if (! appleEvent) |
| 1406 | return false; |
| 1407 | // somewhere add text8 |
| 1408 | NSAppleEventSendOptions nsOptions = (unsigned long) aeOptions; // identical numbers, fortunately |
| 1409 | NSError *error; |
| 1410 | [appleEvent |
| 1411 | sendEventWithOptions: nsOptions |
| 1412 | timeout: (double) timeOut |
| 1413 | error: & error |
| 1414 | ]; |
| 1415 | if (error) |
| 1416 | return false; // event not sent correctly |
| 1417 | return true; // we did send an event to a running non-identical Praat successfully |
| 1418 | } else { |
| 1419 | Melder_crash (U"Unknown Apple Event version."); |
| 1420 | } |
| 1421 | #elif defined (UNIXcxx . . $ `<built-in>:479:9`!) |
| 1422 | autofilecxx . . $ autofile# fcxx . . $ autofile#autofile(49f6e7a06ebc5aa8).; |
| 1423 | try { |
| 1424 | f =cxx . . $ autofile#`operator=`(8d4262d45fc644ab). Melder_fopencxx . . $ Melder_fopen(feb98de266255aea). (& messageFilecxx . . $ messageFile., "w"); |
| 1425 | fprintf (f, "%s", text8.getcxx . . $ _autostring#get(5a2a78a048fb49a8).()); |
| 1426 | f.closecxx . . $ autofile#close(1145552d769d7b5d). (& messageFilecxx . . $ messageFile.); |
| 1427 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 1428 | Melder_clearErrorcxx . . $ Melder_clearError(49f6e7a06ebc5aa8). (); |
| 1429 | Melder_casualcxx . . $ Melder_casual(6298c93241566110). (U"Cannot write message file \"", MelderFile_messageNamecxx . . $ MelderFile_messageName(d9f043369fa9b55b). (& messageFilecxx . . $ messageFile.), |
| 1430 | U"\" (no privilege to write to folder, or disk full)."); |
| 1431 | return false; |
| 1432 | } |
| 1433 | if (kill (pidOfRunningPraat, SIGUSR1cxx . . $ `<external>/1457673850468744829/signum-arch.h:49:9`!)) { |
| 1434 | Melder_casualcxx . . $ Melder_casual(6298c93241566110). (U"Cannot send message. The program may have crashed."); |
| 1435 | return false; |
| 1436 | } |
| 1437 | return true; |
| 1438 | #elif defined (_WIN32) |
| 1439 | autofile f; |
| 1440 | try { |
| 1441 | f = Melder_fopen (& messageFile, "w"); |
| 1442 | fprintf (f, "%s", text8.get()); |
| 1443 | f.close (& messageFile); |
| 1444 | } catch (MelderError) { |
| 1445 | Melder_clearError (); |
| 1446 | Melder_casual (U"Cannot write message file \"", MelderFile_messageName (& messageFile), |
| 1447 | U"\" (no privilege to write to folder, or disk full)."); |
| 1448 | return false; |
| 1449 | } |
| 1450 | if (SendMessage (HWND (theWinApplicationWindow), WM_APP, 0, 0)) { |
| 1451 | Melder_casual (U"Cannot send message."); |
| 1452 | return false; |
| 1453 | } |
| 1454 | return true; |
| 1455 | #endif |
| 1456 | return false; // the default |
| 1457 | } |
| 1458 | |
| 1459 | /* |
| 1460 | This function translates the command-line arguments to fields in `praatP`. |
| 1461 | It doesn't do too much by itself, because many of the relevant entities (such as preferences folder and tracing file) |
| 1462 | haven't been set yet (because setting these entities depends on the command-line arguments). |
| 1463 | */ |
| 1464 | static void interpretCommandLineArgumentscxx . . $ interpretCommandLineArguments(547ee1cda5b77863). (bool weWereStartedFromTheCommandLine, int argc, char **argv) { |
| 1465 | //TRACE // the tracing file may not have been set yet, so this will probably go to stderr |
| 1466 | for (int iarg = 0; iarg < argc; iarg ++) |
| 1467 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"arg ", iarg, U": <<", Melder_peek8to32_u (argv [iarg]), U">>"); |
| 1468 | |
| 1469 | praatPcxx . . $ praatP..argccxx . . $ PraatP#argc. = argc; |
| 1470 | praatPcxx . . $ praatP..argvcxx . . $ PraatP#argv. = argv; |
| 1471 | praatPcxx . . $ praatP..argumentNumbercxx . . $ PraatP#argumentNumber. = 1; |
| 1472 | |
| 1473 | /* |
| 1474 | Running Praat from the command line. |
| 1475 | */ |
| 1476 | while (praatPcxx . . $ praatP..argumentNumbercxx . . $ PraatP#argumentNumber. < argc && argv [praatPcxx . . $ praatP..argumentNumbercxx . . $ PraatP#argumentNumber.] [0] == '-') { |
| 1477 | if (strequcxx . . $ `melder/melder_string32.h:69:9`! (argv [praatPcxx . . $ praatP..argumentNumbercxx . . $ PraatP#argumentNumber.], "-")) { |
| 1478 | praatPcxx . . $ praatP..hasCommandLineInputcxx . . $ PraatP#hasCommandLineInput. = true; |
| 1479 | praatPcxx . . $ praatP..argumentNumbercxx . . $ PraatP#argumentNumber. += 1; |
| 1480 | } else if (strequcxx . . $ `melder/melder_string32.h:69:9`! (argv [praatPcxx . . $ praatP..argumentNumbercxx . . $ PraatP#argumentNumber.], "--run")) { |
| 1481 | praatPcxx . . $ praatP..foundTheRunSwitchcxx . . $ PraatP#foundTheRunSwitch. = true; |
| 1482 | praatPcxx . . $ praatP..argumentNumbercxx . . $ PraatP#argumentNumber. += 1; |
| 1483 | } else if (strequcxx . . $ `melder/melder_string32.h:69:9`! (argv [praatPcxx . . $ praatP..argumentNumbercxx . . $ PraatP#argumentNumber.], "--open")) { |
| 1484 | praatPcxx . . $ praatP..foundTheOpenSwitchcxx . . $ PraatP#foundTheOpenSwitch. = true; |
| 1485 | praatPcxx . . $ praatP..argumentNumbercxx . . $ PraatP#argumentNumber. += 1; |
| 1486 | } else if (strequcxx . . $ `melder/melder_string32.h:69:9`! (argv [praatPcxx . . $ praatP..argumentNumbercxx . . $ PraatP#argumentNumber.], "--new-open")) { |
| 1487 | praatPcxx . . $ praatP..foundTheNewSwitchcxx . . $ PraatP#foundTheNewSwitch. = true; |
| 1488 | praatPcxx . . $ praatP..foundTheOpenSwitchcxx . . $ PraatP#foundTheOpenSwitch. = true; |
| 1489 | praatPcxx . . $ praatP..argumentNumbercxx . . $ PraatP#argumentNumber. += 1; |
| 1490 | } else if (strequcxx . . $ `melder/melder_string32.h:69:9`! (argv [praatPcxx . . $ praatP..argumentNumbercxx . . $ PraatP#argumentNumber.], "--send")) { |
| 1491 | praatPcxx . . $ praatP..foundTheSendSwitchcxx . . $ PraatP#foundTheSendSwitch. = true; |
| 1492 | praatPcxx . . $ praatP..argumentNumbercxx . . $ PraatP#argumentNumber. += 1; |
| 1493 | } else if (strequcxx . . $ `melder/melder_string32.h:69:9`! (argv [praatPcxx . . $ praatP..argumentNumbercxx . . $ PraatP#argumentNumber.], "--new-send")) { |
| 1494 | praatPcxx . . $ praatP..foundTheNewSwitchcxx . . $ PraatP#foundTheNewSwitch. = true; |
| 1495 | praatPcxx . . $ praatP..foundTheSendSwitchcxx . . $ PraatP#foundTheSendSwitch. = true; |
| 1496 | praatPcxx . . $ praatP..argumentNumbercxx . . $ PraatP#argumentNumber. += 1; |
| 1497 | } else if (strequcxx . . $ `melder/melder_string32.h:69:9`! (argv [praatPcxx . . $ praatP..argumentNumbercxx . . $ PraatP#argumentNumber.], "--send-or-form")) { |
| 1498 | praatPcxx . . $ praatP..foundTheSendOrFormSwitchcxx . . $ PraatP#foundTheSendOrFormSwitch. = true; |
| 1499 | praatPcxx . . $ praatP..argumentNumbercxx . . $ PraatP#argumentNumber. += 1; |
| 1500 | } else if (strequcxx . . $ `melder/melder_string32.h:69:9`! (argv [praatPcxx . . $ praatP..argumentNumbercxx . . $ PraatP#argumentNumber.], "--new-send-or-form")) { |
| 1501 | praatPcxx . . $ praatP..foundTheNewSwitchcxx . . $ PraatP#foundTheNewSwitch. = true; |
| 1502 | praatPcxx . . $ praatP..foundTheSendOrFormSwitchcxx . . $ PraatP#foundTheSendOrFormSwitch. = true; |
| 1503 | praatPcxx . . $ praatP..argumentNumbercxx . . $ PraatP#argumentNumber. += 1; |
| 1504 | } else if (strequcxx . . $ `melder/melder_string32.h:69:9`! (argv [praatPcxx . . $ praatP..argumentNumbercxx . . $ PraatP#argumentNumber.], "--FULL-TRUST")) { |
| 1505 | praatPcxx . . $ praatP..fullTrustcxx . . $ PraatP#fullTrust. = true; |
| 1506 | praatPcxx . . $ praatP..argumentNumbercxx . . $ PraatP#argumentNumber. += 1; |
| 1507 | } else if (strequcxx . . $ `melder/melder_string32.h:69:9`! (argv [praatPcxx . . $ praatP..argumentNumbercxx . . $ PraatP#argumentNumber.], "--no-pref-files")) { |
| 1508 | praatPcxx . . $ praatP..ignorePreferenceFilescxx . . $ PraatP#ignorePreferenceFiles. = true; |
| 1509 | praatPcxx . . $ praatP..argumentNumbercxx . . $ PraatP#argumentNumber. += 1; |
| 1510 | } else if (strequcxx . . $ `melder/melder_string32.h:69:9`! (argv [praatPcxx . . $ praatP..argumentNumbercxx . . $ PraatP#argumentNumber.], "--no-plugins")) { |
| 1511 | praatPcxx . . $ praatP..ignorePluginscxx . . $ PraatP#ignorePlugins. = true; |
| 1512 | praatPcxx . . $ praatP..argumentNumbercxx . . $ PraatP#argumentNumber. += 1; |
| 1513 | } else if (strnequcxx . . $ `melder/melder_string32.h:70:9`! (argv [praatPcxx . . $ praatP..argumentNumbercxx . . $ PraatP#argumentNumber.], "--pref-dir=", 11)) { |
| 1514 | Melder_setPreferencesFoldercxx . . $ Melder_setPreferencesFolder(ff00d524ab0355ec). (Melder_peek8to32_u (argv [praatPcxx . . $ praatP..argumentNumbercxx . . $ PraatP#argumentNumber.] + 11)); |
| 1515 | praatPcxx . . $ praatP..argumentNumbercxx . . $ PraatP#argumentNumber. += 1; |
| 1516 | } else if (strequcxx . . $ `melder/melder_string32.h:69:9`! (argv [praatPcxx . . $ praatP..argumentNumbercxx . . $ PraatP#argumentNumber.], "--version")) { |
| 1517 | Melder_informationcxx . . $ Melder_information(3eb398314feba58b). (Melder_upperCaseAppNamecxx . . $ Melder_upperCaseAppName(1912f6684645c851).(), U" ", Melder_appVersionSTRcxx . . $ Melder_appVersionSTR(1912f6684645c851).(), |
| 1518 | U" (", Melder_appMonthSTRcxx . . $ Melder_appMonthSTR(1912f6684645c851).(), U" ", Melder_appDaycxx . . $ Melder_appDay(da6335ded91d79c2).(), U" ", Melder_appYearcxx . . $ Melder_appYear(da6335ded91d79c2).(), U")"); |
| 1519 | exitcxx . . $ exit(44ed87f96534fad7). (0); |
| 1520 | } else if (strequcxx . . $ `melder/melder_string32.h:69:9`! (argv [praatPcxx . . $ praatP..argumentNumbercxx . . $ PraatP#argumentNumber.], "--trace")) { |
| 1521 | Melder_setTracingcxx . . $ Melder_setTracing(b45ddcbc8423892c). (true); |
| 1522 | praatPcxx . . $ praatP..argumentNumbercxx . . $ PraatP#argumentNumber. += 1; |
| 1523 | } else if (strequcxx . . $ `melder/melder_string32.h:69:9`! (argv [praatPcxx . . $ praatP..argumentNumbercxx . . $ PraatP#argumentNumber.], "--hide-picture")) { |
| 1524 | praatPcxx . . $ praatP..commandLineOptionscxx . . $ PraatP#commandLineOptions..hidePicturecxx . . $ PraatP#$anonymous_type_0#hidePicture. = true; |
| 1525 | praatPcxx . . $ praatP..argumentNumbercxx . . $ PraatP#argumentNumber. += 1; |
| 1526 | } else if (strnequcxx . . $ `melder/melder_string32.h:70:9`! (argv [praatPcxx . . $ praatP..argumentNumbercxx . . $ PraatP#argumentNumber.], "--debug=", 8)) { |
| 1527 | Melder_debugcxx . . $ Melder_debug. = atoicxx . . $ atoi(f5ecf3191ed0cd93). (argv [praatPcxx . . $ praatP..argumentNumbercxx . . $ PraatP#argumentNumber.] + 8); |
| 1528 | praatPcxx . . $ praatP..argumentNumbercxx . . $ PraatP#argumentNumber. += 1; |
| 1529 | } else if (strequcxx . . $ `melder/melder_string32.h:69:9`! (argv [praatPcxx . . $ praatP..argumentNumbercxx . . $ PraatP#argumentNumber.], "--help")) { |
| 1530 | MelderInfo_opencxx . . $ MelderInfo_open(49f6e7a06ebc5aa8). (); |
| 1531 | printHelpcxx . . $ printHelp(49f6e7a06ebc5aa8). (); |
| 1532 | MelderInfo_closecxx . . $ MelderInfo_close(49f6e7a06ebc5aa8). (); |
| 1533 | exitcxx . . $ exit(44ed87f96534fad7). (0); |
| 1534 | } else if (strequcxx . . $ `melder/melder_string32.h:69:9`! (argv [praatPcxx . . $ praatP..argumentNumbercxx . . $ PraatP#argumentNumber.], "-8") || strequcxx . . $ `melder/melder_string32.h:69:9`! (argv [praatPcxx . . $ praatP..argumentNumbercxx . . $ PraatP#argumentNumber.], "--utf8")) { |
| 1535 | MelderConsolecxx . . $ MelderConsole/::setEncodingcxx . . $ MelderConsole/setEncoding(b30133ee0cddd54b). (MelderConsolecxx . . $ MelderConsole/::Encodingcxx . . $ MelderConsole/Encoding#::UTF8cxx . . $ MelderConsole/Encoding#UTF8.); |
| 1536 | praatPcxx . . $ praatP..argumentNumbercxx . . $ PraatP#argumentNumber. += 1; |
| 1537 | } else if (strequcxx . . $ `melder/melder_string32.h:69:9`! (argv [praatPcxx . . $ praatP..argumentNumbercxx . . $ PraatP#argumentNumber.], "-u") || strequcxx . . $ `melder/melder_string32.h:69:9`! (argv [praatPcxx . . $ praatP..argumentNumbercxx . . $ PraatP#argumentNumber.], "--utf16")) { |
| 1538 | MelderConsolecxx . . $ MelderConsole/::setEncodingcxx . . $ MelderConsole/setEncoding(b30133ee0cddd54b). (MelderConsolecxx . . $ MelderConsole/::Encodingcxx . . $ MelderConsole/Encoding#::UTF16cxx . . $ MelderConsole/Encoding#UTF16.); |
| 1539 | praatPcxx . . $ praatP..argumentNumbercxx . . $ PraatP#argumentNumber. += 1; |
| 1540 | } else if (strequcxx . . $ `melder/melder_string32.h:69:9`! (argv [praatPcxx . . $ praatP..argumentNumbercxx . . $ PraatP#argumentNumber.], "-a") || strequcxx . . $ `melder/melder_string32.h:69:9`! (argv [praatPcxx . . $ praatP..argumentNumbercxx . . $ PraatP#argumentNumber.], "--ansi")) { |
| 1541 | MelderConsolecxx . . $ MelderConsole/::setEncodingcxx . . $ MelderConsole/setEncoding(b30133ee0cddd54b). (MelderConsolecxx . . $ MelderConsole/::Encodingcxx . . $ MelderConsole/Encoding#::ANSIcxx . . $ MelderConsole/Encoding#ANSI.); |
| 1542 | praatPcxx . . $ praatP..argumentNumbercxx . . $ PraatP#argumentNumber. += 1; |
| 1543 | #if defined (macintosh) |
| 1544 | } else if (strequ (argv [praatP.argumentNumber], "-NSDocumentRevisionsDebugMode")) { |
| 1545 | (void) 0; // ignore this option, which was added by Xcode |
| 1546 | praatP.argumentNumber += 2; // jump over the argument, which is usually "YES" (this jump works correctly even if this argument is missing) |
| 1547 | } else if (strnequ (argv [praatP.argumentNumber], "-psn_", 5)) { |
| 1548 | (void) 0; // ignore this option, which was added by the Finder, perhaps when dragging a file on Praat (Process Serial Number) |
| 1549 | trace (U"Process serial number ", Melder_peek8to32_u (argv [praatP.argumentNumber])); |
| 1550 | praatP.argumentNumber += 1; |
| 1551 | #endif |
| 1552 | } else if (strequcxx . . $ `melder/melder_string32.h:69:9`! (argv [praatPcxx . . $ praatP..argumentNumbercxx . . $ PraatP#argumentNumber.], "-sgi") || |
| 1553 | strequcxx . . $ `melder/melder_string32.h:69:9`! (argv [praatPcxx . . $ praatP..argumentNumbercxx . . $ PraatP#argumentNumber.], "-motif") || |
| 1554 | strequcxx . . $ `melder/melder_string32.h:69:9`! (argv [praatPcxx . . $ praatP..argumentNumbercxx . . $ PraatP#argumentNumber.], "-cde") || |
| 1555 | strequcxx . . $ `melder/melder_string32.h:69:9`! (argv [praatPcxx . . $ praatP..argumentNumbercxx . . $ PraatP#argumentNumber.], "-solaris") || |
| 1556 | strequcxx . . $ `melder/melder_string32.h:69:9`! (argv [praatPcxx . . $ praatP..argumentNumbercxx . . $ PraatP#argumentNumber.], "-hp") || |
| 1557 | strequcxx . . $ `melder/melder_string32.h:69:9`! (argv [praatPcxx . . $ praatP..argumentNumbercxx . . $ PraatP#argumentNumber.], "-sun4") || |
| 1558 | strequcxx . . $ `melder/melder_string32.h:69:9`! (argv [praatPcxx . . $ praatP..argumentNumbercxx . . $ PraatP#argumentNumber.], "-mac") || |
| 1559 | strequcxx . . $ `melder/melder_string32.h:69:9`! (argv [praatPcxx . . $ praatP..argumentNumbercxx . . $ PraatP#argumentNumber.], "-win32") || |
| 1560 | strequcxx . . $ `melder/melder_string32.h:69:9`! (argv [praatPcxx . . $ praatP..argumentNumbercxx . . $ PraatP#argumentNumber.], "-linux") || |
| 1561 | strequcxx . . $ `melder/melder_string32.h:69:9`! (argv [praatPcxx . . $ praatP..argumentNumbercxx . . $ PraatP#argumentNumber.], "-cocoa") || |
| 1562 | strequcxx . . $ `melder/melder_string32.h:69:9`! (argv [praatPcxx . . $ praatP..argumentNumbercxx . . $ PraatP#argumentNumber.], "-chrome") |
| 1563 | ) { |
| 1564 | praatPcxx . . $ praatP..argumentNumbercxx . . $ PraatP#argumentNumber. += 1; |
| 1565 | } else { |
| 1566 | MelderInfo_opencxx . . $ MelderInfo_open(49f6e7a06ebc5aa8). (); |
| 1567 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"Unrecognized command line option ", Melder_peek8to32_u (argv [praatPcxx . . $ praatP..argumentNumbercxx . . $ PraatP#argumentNumber.]), U"\n"); |
| 1568 | printHelpcxx . . $ printHelp(49f6e7a06ebc5aa8). (); |
| 1569 | MelderInfo_closecxx . . $ MelderInfo_close(49f6e7a06ebc5aa8). (); |
| 1570 | exitcxx . . $ exit(44ed87f96534fad7). (-1); |
| 1571 | } |
| 1572 | } |
| 1573 | const bool thereIsAFileNameInTheArgumentList = ( praatPcxx . . $ praatP..argumentNumbercxx . . $ PraatP#argumentNumber. < argc ); |
| 1574 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"Start-up flags: cornsff = ", |
| 1575 | weWereStartedFromTheCommandLine, praatP.foundTheOpenSwitch, praatP.foundTheRunSwitch, |
| 1576 | praatP.foundTheNewSwitch, praatP.foundTheSendSwitch, praatP.foundTheSendOrFormSwitch, thereIsAFileNameInTheArgumentList |
| 1577 | ); |
| 1578 | if (praatPcxx . . $ praatP..foundTheRunSwitchcxx . . $ PraatP#foundTheRunSwitch. && praatPcxx . . $ praatP..foundTheOpenSwitchcxx . . $ PraatP#foundTheOpenSwitch.) { |
| 1579 | MelderInfo_opencxx . . $ MelderInfo_open(49f6e7a06ebc5aa8). (); |
| 1580 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"Conflicting command line switches --run and --open (or --new-open).", U"\n"); |
| 1581 | printHelpcxx . . $ printHelp(49f6e7a06ebc5aa8). (); |
| 1582 | MelderInfo_closecxx . . $ MelderInfo_close(49f6e7a06ebc5aa8). (); |
| 1583 | exitcxx . . $ exit(44ed87f96534fad7). (-1); |
| 1584 | } |
| 1585 | if (praatPcxx . . $ praatP..foundTheRunSwitchcxx . . $ PraatP#foundTheRunSwitch. && praatPcxx . . $ praatP..foundTheSendSwitchcxx . . $ PraatP#foundTheSendSwitch.) { |
| 1586 | MelderInfo_opencxx . . $ MelderInfo_open(49f6e7a06ebc5aa8). (); |
| 1587 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"Conflicting command line switches --run and --send (or --new-send).", U"\n"); |
| 1588 | printHelpcxx . . $ printHelp(49f6e7a06ebc5aa8). (); |
| 1589 | MelderInfo_closecxx . . $ MelderInfo_close(49f6e7a06ebc5aa8). (); |
| 1590 | exitcxx . . $ exit(44ed87f96534fad7). (-1); |
| 1591 | } |
| 1592 | if (praatPcxx . . $ praatP..foundTheRunSwitchcxx . . $ PraatP#foundTheRunSwitch. && praatPcxx . . $ praatP..foundTheSendOrFormSwitchcxx . . $ PraatP#foundTheSendOrFormSwitch.) { |
| 1593 | MelderInfo_opencxx . . $ MelderInfo_open(49f6e7a06ebc5aa8). (); |
| 1594 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"Conflicting command line switches --run and --send-or-form (or --new-send-or-form).", U"\n"); |
| 1595 | printHelpcxx . . $ printHelp(49f6e7a06ebc5aa8). (); |
| 1596 | MelderInfo_closecxx . . $ MelderInfo_close(49f6e7a06ebc5aa8). (); |
| 1597 | exitcxx . . $ exit(44ed87f96534fad7). (-1); |
| 1598 | } |
| 1599 | if (praatPcxx . . $ praatP..foundTheOpenSwitchcxx . . $ PraatP#foundTheOpenSwitch. && praatPcxx . . $ praatP..foundTheSendSwitchcxx . . $ PraatP#foundTheSendSwitch.) { |
| 1600 | MelderInfo_opencxx . . $ MelderInfo_open(49f6e7a06ebc5aa8). (); |
| 1601 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"Conflicting command line switches --open (or --new-open) and --send (or --new-send).", U"\n"); |
| 1602 | printHelpcxx . . $ printHelp(49f6e7a06ebc5aa8). (); |
| 1603 | MelderInfo_closecxx . . $ MelderInfo_close(49f6e7a06ebc5aa8). (); |
| 1604 | exitcxx . . $ exit(44ed87f96534fad7). (-1); |
| 1605 | } |
| 1606 | if (praatPcxx . . $ praatP..foundTheOpenSwitchcxx . . $ PraatP#foundTheOpenSwitch. && praatPcxx . . $ praatP..foundTheSendOrFormSwitchcxx . . $ PraatP#foundTheSendOrFormSwitch.) { |
| 1607 | MelderInfo_opencxx . . $ MelderInfo_open(49f6e7a06ebc5aa8). (); |
| 1608 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"Conflicting command line switches --open (or --new-open) and --send-or-form (or --new-send-or-form).", U"\n"); |
| 1609 | printHelpcxx . . $ printHelp(49f6e7a06ebc5aa8). (); |
| 1610 | MelderInfo_closecxx . . $ MelderInfo_close(49f6e7a06ebc5aa8). (); |
| 1611 | exitcxx . . $ exit(44ed87f96534fad7). (-1); |
| 1612 | } |
| 1613 | if (praatPcxx . . $ praatP..foundTheSendSwitchcxx . . $ PraatP#foundTheSendSwitch. && praatPcxx . . $ praatP..foundTheSendOrFormSwitchcxx . . $ PraatP#foundTheSendOrFormSwitch.) { |
| 1614 | MelderInfo_opencxx . . $ MelderInfo_open(49f6e7a06ebc5aa8). (); |
| 1615 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"Conflicting command line switches --send (or --new-send) and --send-or-form (or --new-send-or-form).", U"\n"); |
| 1616 | printHelpcxx . . $ printHelp(49f6e7a06ebc5aa8). (); |
| 1617 | MelderInfo_closecxx . . $ MelderInfo_close(49f6e7a06ebc5aa8). (); |
| 1618 | exitcxx . . $ exit(44ed87f96534fad7). (-1); |
| 1619 | } |
| 1620 | if (praatPcxx . . $ praatP..foundTheRunSwitchcxx . . $ PraatP#foundTheRunSwitch. && ! thereIsAFileNameInTheArgumentList) { |
| 1621 | MelderInfo_opencxx . . $ MelderInfo_open(49f6e7a06ebc5aa8). (); |
| 1622 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"The switch --run requires a script file name.", U"\n"); |
| 1623 | printHelpcxx . . $ printHelp(49f6e7a06ebc5aa8). (); |
| 1624 | MelderInfo_closecxx . . $ MelderInfo_close(49f6e7a06ebc5aa8). (); |
| 1625 | exitcxx . . $ exit(44ed87f96534fad7). (-1); |
| 1626 | } |
| 1627 | if (praatPcxx . . $ praatP..foundTheSendSwitchcxx . . $ PraatP#foundTheSendSwitch. && ! thereIsAFileNameInTheArgumentList) { |
| 1628 | MelderInfo_opencxx . . $ MelderInfo_open(49f6e7a06ebc5aa8). (); |
| 1629 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"The switch --send requires a script file name.", U"\n"); |
| 1630 | printHelpcxx . . $ printHelp(49f6e7a06ebc5aa8). (); |
| 1631 | MelderInfo_closecxx . . $ MelderInfo_close(49f6e7a06ebc5aa8). (); |
| 1632 | exitcxx . . $ exit(44ed87f96534fad7). (-1); |
| 1633 | } |
| 1634 | if (praatPcxx . . $ praatP..foundTheSendOrFormSwitchcxx . . $ PraatP#foundTheSendOrFormSwitch. && ! thereIsAFileNameInTheArgumentList) { |
| 1635 | MelderInfo_opencxx . . $ MelderInfo_open(49f6e7a06ebc5aa8). (); |
| 1636 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"The switch --send-or-form requires a script file name.", U"\n"); |
| 1637 | printHelpcxx . . $ printHelp(49f6e7a06ebc5aa8). (); |
| 1638 | MelderInfo_closecxx . . $ MelderInfo_close(49f6e7a06ebc5aa8). (); |
| 1639 | exitcxx . . $ exit(44ed87f96534fad7). (-1); |
| 1640 | } |
| 1641 | if (praatPcxx . . $ praatP..foundTheOpenSwitchcxx . . $ PraatP#foundTheOpenSwitch. && ! thereIsAFileNameInTheArgumentList) { |
| 1642 | MelderInfo_opencxx . . $ MelderInfo_open(49f6e7a06ebc5aa8). (); |
| 1643 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"The switch --open requires at least one file name.", U"\n"); |
| 1644 | printHelpcxx . . $ printHelp(49f6e7a06ebc5aa8). (); |
| 1645 | MelderInfo_closecxx . . $ MelderInfo_close(49f6e7a06ebc5aa8). (); |
| 1646 | exitcxx . . $ exit(44ed87f96534fad7). (-1); |
| 1647 | } |
| 1648 | Melder_batchcxx . . $ Melder_batch. = |
| 1649 | ! praatPcxx . . $ praatP..foundTheOpenSwitchcxx . . $ PraatP#foundTheOpenSwitch. && |
| 1650 | ! praatPcxx . . $ praatP..foundTheSendSwitchcxx . . $ PraatP#foundTheSendSwitch. && |
| 1651 | ! praatPcxx . . $ praatP..foundTheSendOrFormSwitchcxx . . $ PraatP#foundTheSendOrFormSwitch. && |
| 1652 | (praatPcxx . . $ praatP..foundTheRunSwitchcxx . . $ PraatP#foundTheRunSwitch. || thereIsAFileNameInTheArgumentList && weWereStartedFromTheCommandLine) // this line to be removed |
| 1653 | ; |
| 1654 | bool userWantsGui = ! Melder_batchcxx . . $ Melder_batch.; |
| 1655 | praatPcxx . . $ praatP..fileNamesCameInByDroppingcxx . . $ PraatP#fileNamesCameInByDropping. = |
| 1656 | userWantsGui && |
| 1657 | ! praatPcxx . . $ praatP..foundTheRunSwitchcxx . . $ PraatP#foundTheRunSwitch. && ! praatPcxx . . $ praatP..foundTheOpenSwitchcxx . . $ PraatP#foundTheOpenSwitch. && ! praatPcxx . . $ praatP..foundTheSendSwitchcxx . . $ PraatP#foundTheSendSwitch. && ! praatPcxx . . $ praatP..foundTheSendOrFormSwitchcxx . . $ PraatP#foundTheSendOrFormSwitch. && |
| 1658 | thereIsAFileNameInTheArgumentList |
| 1659 | ; // doesn't happen on the Mac |
| 1660 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"Did file names come in by dropping? ", praatP.fileNamesCameInByDropping); |
| 1661 | praatPcxx . . $ praatP..userWantsToOpencxx . . $ PraatP#userWantsToOpen. = userWantsGui && (praatPcxx . . $ praatP..foundTheOpenSwitchcxx . . $ PraatP#foundTheOpenSwitch. || praatPcxx . . $ praatP..fileNamesCameInByDroppingcxx . . $ PraatP#fileNamesCameInByDropping.); |
| 1662 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"User wants to open: ", praatP.userWantsToOpen); |
| 1663 | praatPcxx . . $ praatP..userWantsToSendcxx . . $ PraatP#userWantsToSend. = userWantsGui && praatPcxx . . $ praatP..foundTheSendSwitchcxx . . $ PraatP#foundTheSendSwitch.; |
| 1664 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"User wants to send: ", praatP.userWantsToSend); |
| 1665 | praatPcxx . . $ praatP..userWantsToSendOrFormcxx . . $ PraatP#userWantsToSendOrForm. = userWantsGui && praatPcxx . . $ praatP..foundTheSendOrFormSwitchcxx . . $ PraatP#foundTheSendOrFormSwitch.; |
| 1666 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"User wants to send-or-form: ", praatP.userWantsToSendOrForm); |
| 1667 | praatPcxx . . $ praatP..userWantsExistingInstancecxx . . $ PraatP#userWantsExistingInstance. = (praatPcxx . . $ praatP..userWantsToOpencxx . . $ PraatP#userWantsToOpen. || praatPcxx . . $ praatP..userWantsToSendcxx . . $ PraatP#userWantsToSend. || praatPcxx . . $ praatP..userWantsToSendOrFormcxx . . $ PraatP#userWantsToSendOrForm.) && ! praatPcxx . . $ praatP..foundTheNewSwitchcxx . . $ PraatP#foundTheNewSwitch. |
| 1668 | || (userWantsGui && ! weWereStartedFromTheCommandLine); |
| 1669 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"User wants existing instance: ", praatP.userWantsExistingInstance); |
| 1670 | |
| 1671 | if (Melder_batchcxx . . $ Melder_batch. || praatPcxx . . $ praatP..userWantsToSendcxx . . $ PraatP#userWantsToSend. || praatPcxx . . $ praatP..userWantsToSendOrFormcxx . . $ PraatP#userWantsToSendOrForm.) { |
| 1672 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (praatP.argumentNumber < argc); |
| 1673 | /* |
| 1674 | We now get the script file name. It is next on the command line |
| 1675 | (not necessarily *last* on the line, because there may be script arguments after it). |
| 1676 | */ |
| 1677 | MelderString_copycxx . . $ MelderString_copy(65be51a793e0ff96). (& theCurrentPraatApplicationcxx . . $ theCurrentPraatApplication. -> batchNamecxx . . $ structPraatApplication#batchName., Melder_peek8to32_u (argv [praatPcxx . . $ praatP..argumentNumbercxx . . $ PraatP#argumentNumber. ++])); |
| 1678 | if (praatPcxx . . $ praatP..hasCommandLineInputcxx . . $ PraatP#hasCommandLineInput.) |
| 1679 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Cannot have both command line input and a script file."); |
| 1680 | } else { |
| 1681 | MelderString_copycxx . . $ MelderString_copy(65be51a793e0ff96). (& theCurrentPraatApplicationcxx . . $ theCurrentPraatApplication. -> batchNamecxx . . $ structPraatApplication#batchName., U""); |
| 1682 | } |
| 1683 | //Melder_casual (U"Script file name <<", theCurrentPraatApplication -> batchName.string, U">>"); |
| 1684 | |
| 1685 | if (!! thePraatStandAloneScriptTextcxx . . $ thePraatStandAloneScriptText.) { |
| 1686 | Melder_batchcxx . . $ Melder_batch. = true; |
| 1687 | userWantsGui = false; |
| 1688 | if (praatPcxx . . $ praatP..foundTheRunSwitchcxx . . $ PraatP#foundTheRunSwitch.) { |
| 1689 | MelderInfo_opencxx . . $ MelderInfo_open(49f6e7a06ebc5aa8). (); |
| 1690 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"The switch --run is not compatible with running a stand-alone script.", U"\n"); |
| 1691 | printHelpcxx . . $ printHelp(49f6e7a06ebc5aa8). (); |
| 1692 | MelderInfo_closecxx . . $ MelderInfo_close(49f6e7a06ebc5aa8). (); |
| 1693 | exitcxx . . $ exit(44ed87f96534fad7). (-1); |
| 1694 | } |
| 1695 | if (praatPcxx . . $ praatP..foundTheOpenSwitchcxx . . $ PraatP#foundTheOpenSwitch.) { |
| 1696 | MelderInfo_opencxx . . $ MelderInfo_open(49f6e7a06ebc5aa8). (); |
| 1697 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"The switch --open (or --new-open) is not compatible with running a stand-alone script.", U"\n"); |
| 1698 | printHelpcxx . . $ printHelp(49f6e7a06ebc5aa8). (); |
| 1699 | MelderInfo_closecxx . . $ MelderInfo_close(49f6e7a06ebc5aa8). (); |
| 1700 | exitcxx . . $ exit(44ed87f96534fad7). (-1); |
| 1701 | } |
| 1702 | if (praatPcxx . . $ praatP..foundTheSendSwitchcxx . . $ PraatP#foundTheSendSwitch.) { |
| 1703 | MelderInfo_opencxx . . $ MelderInfo_open(49f6e7a06ebc5aa8). (); |
| 1704 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"The switch --send (or --new-send) is not compatible with running a stand-alone script.", U"\n"); |
| 1705 | printHelpcxx . . $ printHelp(49f6e7a06ebc5aa8). (); |
| 1706 | MelderInfo_closecxx . . $ MelderInfo_close(49f6e7a06ebc5aa8). (); |
| 1707 | exitcxx . . $ exit(44ed87f96534fad7). (-1); |
| 1708 | } |
| 1709 | if (praatPcxx . . $ praatP..foundTheSendOrFormSwitchcxx . . $ PraatP#foundTheSendOrFormSwitch.) { |
| 1710 | MelderInfo_opencxx . . $ MelderInfo_open(49f6e7a06ebc5aa8). (); |
| 1711 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"The switch --send-or-form (or --new-send-or-form) is not compatible with running a stand-alone script.", U"\n"); |
| 1712 | printHelpcxx . . $ printHelp(49f6e7a06ebc5aa8). (); |
| 1713 | MelderInfo_closecxx . . $ MelderInfo_close(49f6e7a06ebc5aa8). (); |
| 1714 | exitcxx . . $ exit(44ed87f96534fad7). (-1); |
| 1715 | } |
| 1716 | if (thereIsAFileNameInTheArgumentList) { |
| 1717 | MelderInfo_opencxx . . $ MelderInfo_open(49f6e7a06ebc5aa8). (); |
| 1718 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"Having a file name is not compatible with running a stand-alone script.", U"\n"); |
| 1719 | printHelpcxx . . $ printHelp(49f6e7a06ebc5aa8). (); |
| 1720 | MelderInfo_closecxx . . $ MelderInfo_close(49f6e7a06ebc5aa8). (); |
| 1721 | exitcxx . . $ exit(44ed87f96534fad7). (-1); |
| 1722 | } |
| 1723 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (! praatP.userWantsToOpen); |
| 1724 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (! praatP.userWantsExistingInstance); |
| 1725 | } |
| 1726 | |
| 1727 | /* |
| 1728 | Running the Praat shell from the command line: |
| 1729 | praat - |
| 1730 | */ |
| 1731 | if (praatPcxx . . $ praatP..hasCommandLineInputcxx . . $ PraatP#hasCommandLineInput.) { |
| 1732 | Melder_batchcxx . . $ Melder_batch. = true; |
| 1733 | userWantsGui = false; |
| 1734 | if (praatPcxx . . $ praatP..foundTheRunSwitchcxx . . $ PraatP#foundTheRunSwitch.) { |
| 1735 | MelderInfo_opencxx . . $ MelderInfo_open(49f6e7a06ebc5aa8). (); |
| 1736 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"The switch --run is not compatible with running Praat interactively from the command line.", U"\n"); |
| 1737 | printHelpcxx . . $ printHelp(49f6e7a06ebc5aa8). (); |
| 1738 | MelderInfo_closecxx . . $ MelderInfo_close(49f6e7a06ebc5aa8). (); |
| 1739 | exitcxx . . $ exit(44ed87f96534fad7). (-1); |
| 1740 | } |
| 1741 | if (praatPcxx . . $ praatP..foundTheOpenSwitchcxx . . $ PraatP#foundTheOpenSwitch.) { |
| 1742 | MelderInfo_opencxx . . $ MelderInfo_open(49f6e7a06ebc5aa8). (); |
| 1743 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"The switch --open (or --new-open) is not compatible with running Praat interactively from the command line.", U"\n"); |
| 1744 | printHelpcxx . . $ printHelp(49f6e7a06ebc5aa8). (); |
| 1745 | MelderInfo_closecxx . . $ MelderInfo_close(49f6e7a06ebc5aa8). (); |
| 1746 | exitcxx . . $ exit(44ed87f96534fad7). (-1); |
| 1747 | } |
| 1748 | if (praatPcxx . . $ praatP..foundTheSendSwitchcxx . . $ PraatP#foundTheSendSwitch.) { |
| 1749 | MelderInfo_opencxx . . $ MelderInfo_open(49f6e7a06ebc5aa8). (); |
| 1750 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"The switch --send (or --new-send) is not compatible with running Praat interactively from the command line.", U"\n"); |
| 1751 | printHelpcxx . . $ printHelp(49f6e7a06ebc5aa8). (); |
| 1752 | MelderInfo_closecxx . . $ MelderInfo_close(49f6e7a06ebc5aa8). (); |
| 1753 | exitcxx . . $ exit(44ed87f96534fad7). (-1); |
| 1754 | } |
| 1755 | if (praatPcxx . . $ praatP..foundTheSendOrFormSwitchcxx . . $ PraatP#foundTheSendOrFormSwitch.) { |
| 1756 | MelderInfo_opencxx . . $ MelderInfo_open(49f6e7a06ebc5aa8). (); |
| 1757 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"The switch --send-form (or --new-send-form) is not compatible with running Praat interactively from the command line.", U"\n"); |
| 1758 | printHelpcxx . . $ printHelp(49f6e7a06ebc5aa8). (); |
| 1759 | MelderInfo_closecxx . . $ MelderInfo_close(49f6e7a06ebc5aa8). (); |
| 1760 | exitcxx . . $ exit(44ed87f96534fad7). (-1); |
| 1761 | } |
| 1762 | if (thereIsAFileNameInTheArgumentList) { |
| 1763 | MelderInfo_opencxx . . $ MelderInfo_open(49f6e7a06ebc5aa8). (); |
| 1764 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"Having a file name is not compatible with running Praat interactively from the command line.", U"\n"); |
| 1765 | printHelpcxx . . $ printHelp(49f6e7a06ebc5aa8). (); |
| 1766 | MelderInfo_closecxx . . $ MelderInfo_close(49f6e7a06ebc5aa8). (); |
| 1767 | exitcxx . . $ exit(44ed87f96534fad7). (-1); |
| 1768 | } |
| 1769 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (! praatP.userWantsToOpen); |
| 1770 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (! praatP.userWantsExistingInstance); |
| 1771 | } |
| 1772 | } |
| 1773 | |
| 1774 | static void setPreferencesFoldercxx . . $ setPreferencesFolder(49f6e7a06ebc5aa8). () { |
| 1775 | /* |
| 1776 | Get the app's preferences folder (if not yet set by the --pref-dir option): |
| 1777 | in Praat 6: |
| 1778 | "/home/miep/.praat-dir" (Linux) |
| 1779 | "/Users/miep/Library/Preferences/Praat Prefs" (Mac) |
| 1780 | "C:\Users\Miep\Praat" (Windows) |
| 1781 | in Praat 7: |
| 1782 | $XDG_CONFIG_HOME/praat or else "/home/miep/.config/praat" (Linux) |
| 1783 | "/Users/miep/Library/Application Support/Praat" (Mac) |
| 1784 | "C:\Users\Miep\AppData\Roaming\Praat" (Windows) |
| 1785 | and construct a preferences-file name and a script-buttons-file name like |
| 1786 | /home/miep/.praat-dir/prefs5 |
| 1787 | /home/miep/.praat-dir/buttons5 |
| 1788 | /home/miep/.config/praat/Preferences.txt |
| 1789 | /home/miep/.config/praat/Buttons.txt |
| 1790 | or |
| 1791 | /Users/miep/Library/Preferences/Praat Prefs/Prefs5 |
| 1792 | /Users/miep/Library/Preferences/Praat Prefs/Buttons5 |
| 1793 | /Users/miep/Library/Application Support/Praat/Preferences.txt |
| 1794 | /Users/miep/Library/Application Support/Praat/Buttons.txt |
| 1795 | or |
| 1796 | C:\Users\Miep\Praat\Preferences5.ini |
| 1797 | C:\Users\Miep\Praat\Buttons5.ini |
| 1798 | C:\Users\Miep\AppData\Roaming\Praat\Preferences.txt |
| 1799 | C:\Users\Miep\AppData\Roaming\Praat\Buttons.txt |
| 1800 | Also create names for message and tracing files. |
| 1801 | |
| 1802 | Platform-dependently preferred cache location: |
| 1803 | - same as prefs folder (Mac, Windows) |
| 1804 | - $XDG_CACHE_HOME/praat or else /home/miep/.cache/praat (Linux) |
| 1805 | Platform-dependently preferred log file location: |
| 1806 | - same as prefs folder (Mac, Windows) |
| 1807 | - $XDG_STATE_HOME/praat or else /home/miep/.local/state/praat (Linux) |
| 1808 | Platform-dependently preferred data file location: |
| 1809 | - same as prefs folder (Mac, Windows) |
| 1810 | - $XDG_DATA_HOME/praat or else /home/miep/.local/share/praat (Linux) |
| 1811 | Platform-dependently preferred message file location: |
| 1812 | - same as prefs folder (Mac, Windows) |
| 1813 | - $XDG_RUNTIME_DIR/praat (Linux, access mode 0700) |
| 1814 | */ |
| 1815 | if (MelderFolder_isNullcxx . . $ MelderFolder_isNull(f2f3cbeb84a71ab3). (Melder_preferencesFoldercxx . . $ Melder_preferencesFolder(3f0bf42ba8f9aa29).())) { // not yet set by the --pref-dir option? |
| 1816 | try { |
| 1817 | Melder_setPreferencesFoldercxx . . $ Melder_setPreferencesFolder(ff00d524ab0355ec). (MelderFolder_peekPathcxx . . $ MelderFolder_peekPath(fbe3b4f4d15c56ee). (Melder_preferencesFolder7cxx . . $ Melder_preferencesFolder7(3f0bf42ba8f9aa29).())); |
| 1818 | MelderFolder_createcxx . . $ MelderFolder_create(63f38d3b6b86d1dc). (Melder_preferencesFoldercxx . . $ Melder_preferencesFolder(3f0bf42ba8f9aa29).()); // only version 7 has to be created |
| 1819 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 1820 | /* |
| 1821 | If we arrive here, the directory could not be created, |
| 1822 | and all the files are null. Praat should nevertheless start up. |
| 1823 | */ |
| 1824 | Melder_clearErrorcxx . . $ Melder_clearError(49f6e7a06ebc5aa8). (); |
| 1825 | } |
| 1826 | } |
| 1827 | if (! MelderFolder_isNullcxx . . $ MelderFolder_isNull(f2f3cbeb84a71ab3). (Melder_preferencesFoldercxx . . $ Melder_preferencesFolder(3f0bf42ba8f9aa29).())) { |
| 1828 | /* |
| 1829 | All the version-5 and version-7 paths. |
| 1830 | The version-5 paths will have to be remembered and accessed even in version 7. |
| 1831 | */ |
| 1832 | #if defined (UNIXcxx . . $ `<built-in>:479:9`!) |
| 1833 | MelderFolder_getFilecxx . . $ MelderFolder_getFile(fcdc1f9d1818a0a1). (Melder_preferencesFolder5cxx . . $ Melder_preferencesFolder5(3f0bf42ba8f9aa29).(), U"prefs5", & prefsFile5cxx . . $ prefsFile5.); |
| 1834 | MelderFolder_getFilecxx . . $ MelderFolder_getFile(fcdc1f9d1818a0a1). (Melder_preferencesFolder5cxx . . $ Melder_preferencesFolder5(3f0bf42ba8f9aa29).(), U"buttons5", & buttonsFile5cxx . . $ buttonsFile5.); |
| 1835 | #elif defined (_WIN32) |
| 1836 | MelderFolder_getFile (Melder_preferencesFolder5(), U"Preferences5.ini", & prefsFile5); |
| 1837 | MelderFolder_getFile (Melder_preferencesFolder5(), U"Buttons5.ini", & buttonsFile5); |
| 1838 | #elif defined (macintosh) |
| 1839 | MelderFolder_getFile (Melder_preferencesFolder5(), U"Prefs5", & prefsFile5); |
| 1840 | MelderFolder_getFile (Melder_preferencesFolder5(), U"Buttons5", & buttonsFile5); |
| 1841 | #endif |
| 1842 | /* |
| 1843 | All the version-7 paths. |
| 1844 | It cannot hurt that they are already known in version 6. |
| 1845 | */ |
| 1846 | MelderFolder_getFilecxx . . $ MelderFolder_getFile(fcdc1f9d1818a0a1). (Melder_preferencesFolder7cxx . . $ Melder_preferencesFolder7(3f0bf42ba8f9aa29).(), U"Preferences.txt", & prefsFile7cxx . . $ prefsFile7.); |
| 1847 | MelderFolder_getFilecxx . . $ MelderFolder_getFile(fcdc1f9d1818a0a1). (Melder_preferencesFolder7cxx . . $ Melder_preferencesFolder7(3f0bf42ba8f9aa29).(), U"Buttons.txt", & buttonsFile7cxx . . $ buttonsFile7.); |
| 1848 | MelderFolder_getFilecxx . . $ MelderFolder_getFile(fcdc1f9d1818a0a1). (Melder_preferencesFolder7cxx . . $ Melder_preferencesFolder7(3f0bf42ba8f9aa29).(), U"Tracing.txt", & tracingFilecxx . . $ tracingFile.); |
| 1849 | MelderFolder_getFilecxx . . $ MelderFolder_getFile(fcdc1f9d1818a0a1). (Melder_preferencesFolder7cxx . . $ Melder_preferencesFolder7(3f0bf42ba8f9aa29).(), U"Message.txt", & messageFilecxx . . $ messageFile.); |
| 1850 | #if defined (UNIXcxx . . $ `<built-in>:479:9`!) |
| 1851 | MelderFolder_getFilecxx . . $ MelderFolder_getFile(fcdc1f9d1818a0a1). (Melder_preferencesFolder7cxx . . $ Melder_preferencesFolder7(3f0bf42ba8f9aa29).(), U"pid.txt", & pidFilecxx . . $ pidFile.); |
| 1852 | #endif |
| 1853 | Melder_tracingToFilecxx . . $ Melder_tracingToFile(1145552d769d7b5d). (& tracingFilecxx . . $ tracingFile.); |
| 1854 | } |
| 1855 | } |
| 1856 | |
| 1857 | void praat_initcxx . . $ praat_init(d8f80fb324ce6fc2). (conststring32cxx . . $ conststring32# title, |
| 1858 | conststring32cxx . . $ conststring32# versionText, integercxx . . $ integer# versionNumber, |
| 1859 | integercxx . . $ integer# year, integercxx . . $ integer# month, integercxx . . $ integer# day, |
| 1860 | conststring32cxx . . $ conststring32# firstPartOfEmailAddress, conststring32cxx . . $ conststring32# secondPartOfEmailAddress, |
| 1861 | int argc, char **argv |
| 1862 | ) { |
| 1863 | setThePraatLocalecxx . . $ setThePraatLocale(49f6e7a06ebc5aa8). (); |
| 1864 | Melder_initcxx . . $ Melder_init(49f6e7a06ebc5aa8). (); |
| 1865 | const bool weWereStartedFromTheCommandLine = tryToAttachToTheCommandLinecxx . . $ tryToAttachToTheCommandLine(c9857a73d68e59ba). (); |
| 1866 | MelderConsole_initcxx . . $ MelderConsole_init(49f6e7a06ebc5aa8). (); |
| 1867 | |
| 1868 | /* |
| 1869 | Construct a main-window title like "Praat". |
| 1870 | Construct an app name like "praat" for file and folder names. |
| 1871 | */ |
| 1872 | Melder_setAppNamecxx . . $ Melder_setAppName(ff00d524ab0355ec). (title && title [0] != U'\0' ? title : U"Praat"); |
| 1873 | Melder_setAppVersioncxx . . $ Melder_setAppVersion(940f97f64241106a). (versionText, versionNumber); |
| 1874 | Melder_setAppDatecxx . . $ Melder_setAppDate(1accef8d191cd3cf). (year, month, day); |
| 1875 | Melder_setAppContactAddresscxx . . $ Melder_setAppContactAddress(cc7657622ff166ed). (firstPartOfEmailAddress, secondPartOfEmailAddress); |
| 1876 | |
| 1877 | /* |
| 1878 | Get the home folder, e.g. "/home/miep/", or "/Users/miep/", or just "/". |
| 1879 | */ |
| 1880 | Melder_getHomeDircxx . . $ Melder_getHomeDir(63f38d3b6b86d1dc). (& homeDircxx . . $ homeDir.); |
| 1881 | |
| 1882 | interpretCommandLineArgumentscxx . . $ interpretCommandLineArguments(547ee1cda5b77863). (weWereStartedFromTheCommandLine, argc, argv); |
| 1883 | |
| 1884 | setPreferencesFoldercxx . . $ setPreferencesFolder(49f6e7a06ebc5aa8). (); |
| 1885 | |
| 1886 | /* |
| 1887 | Remember the current directory. Useful only for scripts run from batch. |
| 1888 | */ |
| 1889 | Melder_rememberShellDirectorycxx . . $ Melder_rememberShellDirectory(49f6e7a06ebc5aa8). (); |
| 1890 | |
| 1891 | installPraatShellPreferencescxx . . $ installPraatShellPreferences(49f6e7a06ebc5aa8). (); |
| 1892 | |
| 1893 | theCurrentPraatApplicationcxx . . $ theCurrentPraatApplication. -> batchcxx . . $ structPraatApplication#batch. = Melder_batchcxx . . $ Melder_batch.; |
| 1894 | |
| 1895 | #if defined (NO_GUI) |
| 1896 | if (! Melder_batch) { |
| 1897 | fprintf (Melder_stderr, "A no-GUI edition of Praat cannot be used interactively. " |
| 1898 | "Supply \"--run\" and a script file name on the command line.\n"); |
| 1899 | exit (1); |
| 1900 | } |
| 1901 | #endif |
| 1902 | |
| 1903 | /* |
| 1904 | Check whether we can transfer control to an already running instance of Praat. |
| 1905 | */ |
| 1906 | #if defined (macintosh) |
| 1907 | NSApplication *theApp = [GuiCocoaApplication sharedApplication]; // initialize, so that our bundle identifier exists even if we started from outside Xcode |
| 1908 | #elif defined (_WIN32) |
| 1909 | theWinApplicationWindow = GuiWin_initialize1 (Melder_upperCaseAppName()); |
| 1910 | #endif |
| 1911 | if (praatPcxx . . $ praatP..userWantsExistingInstancecxx . . $ PraatP#userWantsExistingInstance.) |
| 1912 | if (tryToSwitchToRunningPraatcxx . . $ tryToSwitchToRunningPraat(c7f7a522d592f53e). (praatPcxx . . $ praatP..userWantsToOpencxx . . $ PraatP#userWantsToOpen., praatPcxx . . $ praatP..userWantsToSendcxx . . $ PraatP#userWantsToSend., praatPcxx . . $ praatP..userWantsToSendOrFormcxx . . $ PraatP#userWantsToSendOrForm.)) |
| 1913 | exitcxx . . $ exit(44ed87f96534fad7). (0); |
| 1914 | |
| 1915 | #ifdef UNIXcxx . . $ `<built-in>:479:9`! |
| 1916 | if (! Melder_batchcxx . . $ Melder_batch.) { |
| 1917 | /* |
| 1918 | Write our process id into the pid file. |
| 1919 | Messages from "sendpraat" are caught very early this way, |
| 1920 | though they will be responded to much later. |
| 1921 | */ |
| 1922 | try { |
| 1923 | autofilecxx . . $ autofile# f = Melder_fopencxx . . $ autofile#autofile(8d4262d45fc644ab). (& pidFilecxx . . $ pidFile., "w"); |
| 1924 | fprintf (f, "%td %td", integercxx . . $ integer# (getpid ()), integercxx . . $ integer# (Melder_appVersioncxx . . $ Melder_appVersion(da6335ded91d79c2).())); |
| 1925 | f.closecxx . . $ autofile#close(1145552d769d7b5d). (& pidFilecxx . . $ pidFile.); |
| 1926 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 1927 | Melder_clearErrorcxx . . $ Melder_clearError(49f6e7a06ebc5aa8). (); |
| 1928 | } |
| 1929 | } |
| 1930 | #endif |
| 1931 | #if defined (_WIN32) |
| 1932 | if (! Melder_batch) |
| 1933 | motif_win_setUserMessageCallback (cb_userMessage); |
| 1934 | #endif |
| 1935 | #if defined (macintosh) |
| 1936 | if (! Melder_batch) |
| 1937 | mac_setUserMessageCallback (cb_userMessage); // not earlier |
| 1938 | #endif |
| 1939 | Gui_setQuitApplicationCallbackcxx . . $ Gui_setQuitApplicationCallback(964b12a25712bdc3). (cb_quitApplicationcxx . . $ cb_quitApplication(49f6e7a06ebc5aa8).); |
| 1940 | |
| 1941 | GuiWindowcxx . . $ GuiWindow# raam = nullptr; |
| 1942 | if (! Melder_batchcxx . . $ Melder_batch.) { |
| 1943 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"starting the GUI application"); |
| 1944 | Machine_initLookAndFeelcxx . . $ Machine_initLookAndFeel(c759356ac01a31e7). (argc, argv); |
| 1945 | #if gtkcxx . . $ `sys/Gui.h:33:10`! |
| 1946 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"locale ", Melder_peek8to32_u (setlocale (LC_ALLcxx . . $ `<external>/3736975272097309885/locale.h:41:9`!, nullptr))); |
| 1947 | g_set_application_name (Melder_peek32to8 (title)); |
| 1948 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"locale ", Melder_peek8to32_u (setlocale (LC_ALLcxx . . $ `<external>/3736975272097309885/locale.h:41:9`!, nullptr))); |
| 1949 | #elif motif |
| 1950 | GuiWin_initialize2 (argc, argv); |
| 1951 | #elif cocoa |
| 1952 | /* |
| 1953 | We want to get rid of the Search field in the help menu. |
| 1954 | By default, such a Search field will come up automatically when we create a menu with the title "Help". |
| 1955 | By changing this title to "SomeFakeTitleOfAMenuThatWillNeverBeInstantiated", |
| 1956 | we trick macOS into thinking that our help menu is called "SomeFakeTitleOfAMenuThatWillNeverBeInstantiated". |
| 1957 | As a result, the Search field will come up only when we create a menu |
| 1958 | titled "SomeFakeTitleOfAMenuThatWillNeverBeInstantiated", which is never. |
| 1959 | */ |
| 1960 | theApp.helpMenu = [[NSMenu alloc] initWithTitle:@"SomeFakeTitleOfAMenuThatWillNeverBeInstantiated"]; |
| 1961 | #endif |
| 1962 | |
| 1963 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"creating and installing the Objects window"); |
| 1964 | char32cxx . . $ char32# objectWindowTitle [100]; |
| 1965 | Melder_sprintcxx . . $ Melder_sprint(2b992b0fb5123bdf). (objectWindowTitle,100, Melder_upperCaseAppNamecxx . . $ Melder_upperCaseAppName(1912f6684645c851).(), U" Objects"); |
| 1966 | double x, y; |
| 1967 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"locale ", Melder_peek8to32_u (setlocale (LC_ALLcxx . . $ `<external>/3736975272097309885/locale.h:41:9`!, nullptr))); |
| 1968 | Gui_getWindowPositioningBoundscxx . . $ Gui_getWindowPositioningBounds(dec26d86168e59a). (& x, & y, nullptr, nullptr); |
| 1969 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"locale ", Melder_peek8to32_u (setlocale (LC_ALLcxx . . $ `<external>/3736975272097309885/locale.h:41:9`!, nullptr))); |
| 1970 | theCurrentPraatApplicationcxx . . $ theCurrentPraatApplication. -> topShellcxx . . $ structPraatApplication#topShell. = raam = GuiWindow_createcxx . . $ GuiWindow_create(f24bfc1968593561). (x + 10, y, WINDOW_WIDTHcxx . . $ `sys/praat.cpp:53:9`!, WINDOW_HEIGHTcxx . . $ `sys/praat.cpp:54:9`!, 450, 250, |
| 1971 | objectWindowTitle, gui_cb_quitcxx . . $ MelderCallback#MelderCallback(fc624d2cd197112)., nullptr, 0); |
| 1972 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"locale ", Melder_peek8to32_u (setlocale (LC_ALLcxx . . $ `<external>/3736975272097309885/locale.h:41:9`!, nullptr))); |
| 1973 | #if motifcxx . . $ `sys/Gui.h:34:10`! |
| 1974 | GuiApp_setApplicationShell (theCurrentPraatApplication -> topShell -> d_xmShell); |
| 1975 | #endif |
| 1976 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"before objects window shows locale ", Melder_peek8to32_u (setlocale (LC_ALLcxx . . $ `<external>/3736975272097309885/locale.h:41:9`!, nullptr))); |
| 1977 | GuiThing_showcxx . . $ GuiThing_show(20e88c25f0ba841). (raam); |
| 1978 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"after objects window shows locale ", Melder_peek8to32_u (setlocale (LC_ALLcxx . . $ `<external>/3736975272097309885/locale.h:41:9`!, nullptr))); |
| 1979 | } |
| 1980 | Thing_recognizeClassesByNamecxx . . $ Thing_recognizeClassesByName(f327490b5edb0dcb). (classCollectioncxx . . $ classCollection., classStringscxx . . $ classStrings., classManPagescxx . . $ classManPages., classStringSetcxx . . $ classStringSet.); |
| 1981 | Thing_recognizeClassByOtherNamecxx . . $ Thing_recognizeClassByOtherName(cb82456e35792de1). (classStringSetcxx . . $ classStringSet., U"SortedSetOfString"); |
| 1982 | if (Melder_batchcxx . . $ Melder_batch.) { |
| 1983 | Melder_backgroundingcxx . . $ Melder_backgrounding. = true; |
| 1984 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"adding menus without GUI"); |
| 1985 | praat_addMenuscxx . . $ praat_addMenus(20efc9fbfef198b1). (nullptr); |
| 1986 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"adding fixed buttons without GUI"); |
| 1987 | praat_addFixedButtonscxx . . $ praat_addFixedButtons(20efc9fbfef198b1). (nullptr); |
| 1988 | } else { |
| 1989 | #ifdef macintosh |
| 1990 | trace (U"initializing the Gui early (MacOS)"); |
| 1991 | AEInstallEventHandler (758934755, 0, (AEEventHandlerProcPtr) (mac_processSignal8), 0, false); // for receiving sendpraat |
| 1992 | injectMessageAndInformationProcs (raam); // BUG: default Melder_assert would call printf recursively!!! |
| 1993 | #endif |
| 1994 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"creating the menu bar in the Objects window"); |
| 1995 | GuiWindow_addMenuBarcxx . . $ GuiWindow_addMenuBar(20efc9fbfef198b1). (raam); |
| 1996 | praatPcxx . . $ praatP..menuBarcxx . . $ PraatP#menuBar. = raam; |
| 1997 | praat_addMenuscxx . . $ praat_addMenus(20efc9fbfef198b1). (praatPcxx . . $ praatP..menuBarcxx . . $ PraatP#menuBar.); |
| 1998 | |
| 1999 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"creating the object list in the Objects window"); |
| 2000 | GuiLabel_createShowncxx . . $ GuiLabel_createShown(39026c9008a6a07). (raam, 3, -250, Machine_getMenuBarBottomcxx . . $ Machine_getMenuBarBottom(b126dc7c1de90089). () + 5, Machine_getMenuBarBottomcxx . . $ Machine_getMenuBarBottom(b126dc7c1de90089). () + 5 + Gui_LABEL_HEIGHTcxx . . $ `sys/Gui.h:97:9`!, U"Objects:", 0); |
| 2001 | praatList_objectscxx . . $ praatList_objects. = GuiList_createcxx . . $ GuiList_create(88aee17cb4a88a62). (raam, 0, -250, Machine_getMenuBarBottomcxx . . $ Machine_getMenuBarBottom(b126dc7c1de90089). () + 26, -100, true, U" Objects "); |
| 2002 | GuiList_setSelectionChangedCallbackcxx . . $ GuiList_setSelectionChangedCallback(4a4684c95b017ef2). (praatList_objectscxx . . $ praatList_objects., gui_cb_list_selectionChangedcxx . . $ MelderCallback#MelderCallback(fc624d2cd197112)., nullptr); |
| 2003 | GuiThing_showcxx . . $ GuiThing_show(20e88c25f0ba841). (praatList_objectscxx . . $ praatList_objects.); |
| 2004 | praat_addFixedButtonscxx . . $ praat_addFixedButtons(20efc9fbfef198b1). (raam); |
| 2005 | |
| 2006 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"creating the dynamic menu in the Objects window"); |
| 2007 | praat_actions_createDynamicMenucxx . . $ praat_actions_createDynamicMenu(20efc9fbfef198b1). (raam); |
| 2008 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"showing the Objects window"); |
| 2009 | GuiThing_showcxx . . $ GuiThing_show(20e88c25f0ba841). (raam); |
| 2010 | #ifdef UNIXcxx . . $ `<built-in>:479:9`! |
| 2011 | if (! praatPcxx . . $ praatP..ignorePreferenceFilescxx . . $ PraatP#ignorePreferenceFiles.) { |
| 2012 | /* |
| 2013 | TODO: explain why this is needed here. |
| 2014 | could have to do with e.g. the font size setting in praat_picture_init, though that shoudl also be handlable by praat_picture_prefsChanged |
| 2015 | or don't Graphics_setFontSize and/or Picture_setMouseSelectsInnerViewport work in that situation? |
| 2016 | */ |
| 2017 | Preferences_read_icxx . . $ Preferences_read_i(1145552d769d7b5d). (& prefsFile5cxx . . $ prefsFile5.); // Read the old settings first... |
| 2018 | Preferences_read_icxx . . $ Preferences_read_i(1145552d769d7b5d). (& prefsFile7cxx . . $ prefsFile7.); // ... and the new settings second. |
| 2019 | } |
| 2020 | #endif |
| 2021 | #if ! defined (macintosh) |
| 2022 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"initializing the Gui late (Windows and Linux)"); |
| 2023 | injectMessageAndInformationProcscxx . . $ injectMessageAndInformationProcs(20efc9fbfef198b1). (theCurrentPraatApplicationcxx . . $ theCurrentPraatApplication. -> topShellcxx . . $ structPraatApplication#topShell.); // Mac: done this earlier |
| 2024 | #endif |
| 2025 | Melder_setHelpProccxx . . $ Melder_setHelpProc(f441b548652834d9). (helpProccxx . . $ helpProc(ff00d524ab0355ec).); |
| 2026 | } |
| 2027 | Data_setPublishProccxx . . $ Data_setPublishProc(222770ccd595104f). (publishProccxx . . $ publishProc(795020d01765d2fa).); |
| 2028 | theCurrentPraatApplicationcxx . . $ theCurrentPraatApplication. -> manPagescxx . . $ structPraatApplication#manPages. = ManPages_createcxx . . $ ManPages_create(91bc9ea8e9e57ef). ().releaseToAmbiguousOwnercxx . . $ autoSomeThing#releaseToAmbiguousOwner(258ee1c9e0a18a5c).(); |
| 2029 | |
| 2030 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"creating the Picture window"); |
| 2031 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"before picture window shows: locale is ", Melder_peek8to32_u (setlocale (LC_ALLcxx . . $ `<external>/3736975272097309885/locale.h:41:9`!, nullptr))); |
| 2032 | if (! praatPcxx . . $ praatP..dontUsePictureWindowcxx . . $ PraatP#dontUsePictureWindow.) |
| 2033 | praat_picture_initcxx . . $ praat_picture_init(b45ddcbc8423892c). (! praatPcxx . . $ praatP..commandLineOptionscxx . . $ PraatP#commandLineOptions..hidePicturecxx . . $ PraatP#$anonymous_type_0#hidePicture.); |
| 2034 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"after picture window shows: locale is ", Melder_peek8to32_u (setlocale (LC_ALLcxx . . $ `<external>/3736975272097309885/locale.h:41:9`!, nullptr))); |
| 2035 | } |
| 2036 | |
| 2037 | static void executeStartUpFilecxx . . $ executeStartUpFile(4824e92520343138). (MelderFoldercxx . . $ MelderFolder# startUpDirectory, conststring32cxx . . $ conststring32# fileNameHead, conststring32cxx . . $ conststring32# fileNameTail) { |
| 2038 | char32cxx . . $ char32# name [256]; |
| 2039 | Melder_sprintcxx . . $ Melder_sprint(2b992b0fb5123bdf). (name,256, fileNameHead, Melder_lowerCaseAppNamecxx . . $ Melder_lowerCaseAppName(1912f6684645c851).(), fileNameTail); |
| 2040 | if (! MelderFolder_isNullcxx . . $ MelderFolder_isNull(f2f3cbeb84a71ab3). (startUpDirectory)) { // should not occur on modern systems |
| 2041 | structMelderFilecxx . . $ structMelderFile# startUp { }; |
| 2042 | MelderFolder_getFilecxx . . $ MelderFolder_getFile(fcdc1f9d1818a0a1). (startUpDirectory, name, & startUp); |
| 2043 | if (! MelderFile_readablecxx . . $ MelderFile_readable(8f92cdf95b27d908). (& startUp)) |
| 2044 | return; // it's OK if the file doesn't exist |
| 2045 | try { |
| 2046 | praat_executeScript_noGUIcxx . . $ praat_executeScript_noGUI(36849bf2e291e39f). (& startUp, false); |
| 2047 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 2048 | Melder_flushErrorcxx . . $ Melder_flushError(6298c93241566110). (Melder_upperCaseAppNamecxx . . $ Melder_upperCaseAppName(1912f6684645c851).(), U": start-up file ", & startUp, U" not completed."); |
| 2049 | } |
| 2050 | } |
| 2051 | } |
| 2052 | |
| 2053 | #if gtkcxx . . $ `sys/Gui.h:33:10`! |
| 2054 | #include <gdk/gdkkeysyms.h> |
| 2055 | static gint theKeySnoopercxx . . $ theKeySnooper(8197e4767abdb7c6). (GtkWidget *widget, GdkEventKey *event, gpointer data) { |
| 2056 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"keyval ", event -> keyval, U", type ", event -> type); |
| 2057 | if ((event -> keyvalcxx . . $ _GdkEventKey#keyval. == GDK_KEY_Tabcxx . . $ `<external>/1674857343504785238/gdkkeysyms.h:41:9`! || event -> keyvalcxx . . $ _GdkEventKey#keyval. == GDK_KEY_ISO_Left_Tabcxx . . $ `<external>/1674857343504785238/gdkkeysyms.h:230:9`!) && event -> typecxx . . $ _GdkEventKey#type. == GDK_KEY_PRESS) { |
| 2058 | using TabCallbackcxx . . $ theKeySnooper(8197e4767abdb7c6).TabCallback# = void (*) (GuiObjectcxx . . $ GuiObject#, gpointer); |
| 2059 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"tab key pressed in window ", Melder_pointer (widget)); |
| 2060 | constexpr bool theTabKeyShouldWorkEvenIfNumLockIsOn = true; |
| 2061 | constexpr uint32cxx . . $ uint32# theProbableNumLockModifierMask = GDK_MOD2_MASK; |
| 2062 | constexpr uint32cxx . . $ uint32# modifiersToIgnore = ( theTabKeyShouldWorkEvenIfNumLockIsOn ? theProbableNumLockModifierMask : 0 ); |
| 2063 | constexpr uint32cxx . . $ uint32# modifiersNotToIgnore = GDK_MODIFIER_MASK & ~ modifiersToIgnore; |
| 2064 | if ((event -> statecxx . . $ _GdkEventKey#state. & modifiersNotToIgnore) == 0) { |
| 2065 | if (GTK_IS_WINDOWcxx . . $ `<external>/3777575239456597881/gtkwindow.h:42:9`! (widget)) { |
| 2066 | GtkWidget *shell = gtk_widget_get_toplevel (GTK_WIDGETcxx . . $ `<external>/6031079988677191796/gtkwidget.h:58:9`! (widget)); |
| 2067 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"tab pressed in GTK window ", Melder_pointer (shell)); |
| 2068 | TabCallbackcxx . . $ theKeySnooper(8197e4767abdb7c6).TabCallback# tabCallback = (TabCallbackcxx . . $ theKeySnooper(8197e4767abdb7c6).TabCallback#) g_object_get_data (G_OBJECTcxx . . $ `<external>/1341695927569185362/gobject.h:54:9`! (widget), "tabCallback"); |
| 2069 | if (tabCallback) { |
| 2070 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"a tab callback exists"); |
| 2071 | void *tabClosure = g_object_get_data (G_OBJECTcxx . . $ `<external>/1341695927569185362/gobject.h:54:9`! (widget), "tabClosure"); |
| 2072 | tabCallback (widget, tabClosure); |
| 2073 | return true; |
| 2074 | } |
| 2075 | } |
| 2076 | } else if ((event -> statecxx . . $ _GdkEventKey#state. & modifiersNotToIgnore) == GDK_SHIFT_MASK) { |
| 2077 | if (GTK_IS_WINDOWcxx . . $ `<external>/3777575239456597881/gtkwindow.h:42:9`! (widget)) { |
| 2078 | GtkWidget *shell = gtk_widget_get_toplevel (GTK_WIDGETcxx . . $ `<external>/6031079988677191796/gtkwidget.h:58:9`! (widget)); |
| 2079 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"shift-tab pressed in GTK window ", Melder_pointer (shell)); |
| 2080 | TabCallbackcxx . . $ theKeySnooper(8197e4767abdb7c6).TabCallback# tabCallback = (TabCallbackcxx . . $ theKeySnooper(8197e4767abdb7c6).TabCallback#) g_object_get_data (G_OBJECTcxx . . $ `<external>/1341695927569185362/gobject.h:54:9`! (widget), "shiftTabCallback"); |
| 2081 | if (tabCallback) { |
| 2082 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"a shift tab callback exists"); |
| 2083 | void *tabClosure = g_object_get_data (G_OBJECTcxx . . $ `<external>/1341695927569185362/gobject.h:54:9`! (widget), "shiftTabClosure"); |
| 2084 | tabCallback (widget, tabClosure); |
| 2085 | return true; |
| 2086 | } |
| 2087 | } |
| 2088 | } |
| 2089 | } |
| 2090 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"end"); |
| 2091 | return false; // pass event on |
| 2092 | } |
| 2093 | #endif |
| 2094 | |
| 2095 | void praat_runcxx . . $ praat_run(49f6e7a06ebc5aa8). () { |
| 2096 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"adding menus, second round"); |
| 2097 | praat_addMenus2cxx . . $ praat_addMenus2(49f6e7a06ebc5aa8). (); |
| 2098 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"locale is ", Melder_peek8to32_u (setlocale (LC_ALLcxx . . $ `<external>/3736975272097309885/locale.h:41:9`!, nullptr))); |
| 2099 | |
| 2100 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"adding the Quit command"); |
| 2101 | praat_addMenuCommandcxx . . $ `sys/praat.h:116:9`! (U"Objects", U"Praat", U"-- quit --", nullptr, 0, nullptr); |
| 2102 | praat_addMenuCommandcxx . . $ `sys/praat.h:116:9`! (U"Objects", U"Praat", Melder_cat (U"Quit ", Melder_upperCaseAppName ()), nullptr, GuiMenu_UNHIDABLEcxx . . $ `sys/Gui.h:870:9`! | 'Q' | GuiMenu_NO_APIcxx . . $ `sys/Gui.h:871:9`!, DO_Quit); |
| 2103 | praat_addMenuCommandcxx . . $ `sys/praat.h:116:9`! (U"Objects", U"Praat", U"Quit", nullptr, GuiMenu_HIDDENcxx . . $ `sys/Gui.h:869:9`! | GuiMenu_NO_APIcxx . . $ `sys/Gui.h:871:9`!, DO_Quit); |
| 2104 | |
| 2105 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"read the preferences file, and notify those who want to be notified of this"); |
| 2106 | /* ...namely, those who already have a window (namely, the Picture window), |
| 2107 | * and those that regard the start of a new session as a meaningful event |
| 2108 | * (namely, the session counter and the cross-session memory counter). |
| 2109 | */ |
| 2110 | if (! praatPcxx . . $ praatP..ignorePreferenceFilescxx . . $ PraatP#ignorePreferenceFiles.) { |
| 2111 | Preferences_read_icxx . . $ Preferences_read_i(1145552d769d7b5d). (& prefsFile5cxx . . $ prefsFile5.); // Read the old settings first... |
| 2112 | Preferences_read_icxx . . $ Preferences_read_i(1145552d769d7b5d). (& prefsFile7cxx . . $ prefsFile7.); // ... and the new settings second. |
| 2113 | if (! praatPcxx . . $ praatP..dontUsePictureWindowcxx . . $ PraatP#dontUsePictureWindow.) |
| 2114 | praat_picture_prefsChangedcxx . . $ praat_picture_prefsChanged(49f6e7a06ebc5aa8). (); |
| 2115 | praat_statistics_prefsChangedcxx . . $ praat_statistics_prefsChanged(49f6e7a06ebc5aa8). (); |
| 2116 | } |
| 2117 | |
| 2118 | praatPcxx . . $ praatP..phasecxx . . $ PraatP#phase. = praat_STARTING_UPcxx . . $ `sys/praatP.h:94:9`!; |
| 2119 | |
| 2120 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"execute start-up file(s)"); |
| 2121 | /* |
| 2122 | On Unix and the Mac, we try no less than three start-up file names. |
| 2123 | */ |
| 2124 | if (Melder_appVersioncxx . . $ Melder_appVersion(da6335ded91d79c2).() < 7000) { |
| 2125 | #if defined (UNIXcxx . . $ `<built-in>:479:9`!) || defined (macintosh) |
| 2126 | structMelderFoldercxx . . $ structMelderFolder# usrLocal { }; |
| 2127 | Melder_pathToFoldercxx . . $ Melder_pathToFolder(f9a4643b225086b8). (U"/usr/local", & usrLocal); |
| 2128 | executeStartUpFilecxx . . $ executeStartUpFile(4824e92520343138). (& usrLocal, U"", U"-startUp"); |
| 2129 | #endif |
| 2130 | #if defined (UNIXcxx . . $ `<built-in>:479:9`!) || defined (macintosh) |
| 2131 | executeStartUpFilecxx . . $ executeStartUpFile(4824e92520343138). (& homeDircxx . . $ homeDir., U".", U"-user-startUp"); // not on Windows (empty file name error) |
| 2132 | #endif |
| 2133 | #if defined (UNIXcxx . . $ `<built-in>:479:9`!) || defined (macintosh) || defined (_WIN32) |
| 2134 | executeStartUpFilecxx . . $ executeStartUpFile(4824e92520343138). (& homeDircxx . . $ homeDir., U"", U"-user-startUp"); |
| 2135 | #endif |
| 2136 | } else { |
| 2137 | // use plug-ins instead |
| 2138 | } |
| 2139 | |
| 2140 | autoSTRVECcxx . . $ autoSTRVEC# pluginFolderNames7cxx . . $ _autostringautovector#_autostringautovector(49f6e7a06ebc5aa8)., pluginFolderNames5cxx . . $ _autostringautovector#_autostringautovector(49f6e7a06ebc5aa8).; |
| 2141 | if (! MelderFolder_isNullcxx . . $ MelderFolder_isNull(f2f3cbeb84a71ab3). (Melder_preferencesFolder7cxx . . $ Melder_preferencesFolder7(3f0bf42ba8f9aa29).()) && ! praatPcxx . . $ praatP..ignorePluginscxx . . $ PraatP#ignorePlugins.) { |
| 2142 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"initialize plug-ins (", MelderFolder_peekPath (Melder_preferencesFolder7()), U")"); |
| 2143 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"locale is ", Melder_peek8to32_u (setlocale (LC_ALLcxx . . $ `<external>/3736975272097309885/locale.h:41:9`!, nullptr))); |
| 2144 | /* |
| 2145 | The Praat phase should remain praat_STARTING_UP, |
| 2146 | because any added commands must not be included in the buttons file. |
| 2147 | In plug-ins, pause windows should therefore be made modal. |
| 2148 | */ |
| 2149 | structMelderFilecxx . . $ structMelderFile# searchPattern { }; |
| 2150 | MelderFolder_getFilecxx . . $ MelderFolder_getFile(fcdc1f9d1818a0a1). (Melder_preferencesFolder7cxx . . $ Melder_preferencesFolder7(3f0bf42ba8f9aa29).(), U"plugin_*", & searchPattern); |
| 2151 | try { |
| 2152 | pluginFolderNames7 =cxx . . $ _autostringautovector#`operator=`(150f7ba7aac25b7e). folderNames_STRVECcxx . . $ folderNames_STRVEC(d3c03a92d990d008). (MelderFile_peekPathcxx . . $ MelderFile_peekPath(d9f043369fa9b55b). (& searchPattern)); |
| 2153 | for (integercxx . . $ integer# i = 1; i <= pluginFolderNames7.sizecxx . . $ _autostringautovector#size.; i ++) { |
| 2154 | structMelderFoldercxx . . $ structMelderFolder# pluginFolder { }; |
| 2155 | structMelderFilecxx . . $ structMelderFile# plugin { }; |
| 2156 | MelderFolder_getSubfoldercxx . . $ MelderFolder_getSubfolder(a6a48bbd99ea6094). (Melder_preferencesFolder7cxx . . $ Melder_preferencesFolder7(3f0bf42ba8f9aa29).(), pluginFolderNames7 [cxx . . $ _autostringautovector#`operator[]`(f191be2b65019068).i].getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), & pluginFolder); |
| 2157 | MelderFolder_getFilecxx . . $ MelderFolder_getFile(fcdc1f9d1818a0a1). (& pluginFolder, U"setup.praat", & plugin); |
| 2158 | if (MelderFile_readablecxx . . $ MelderFile_readable(8f92cdf95b27d908). (& plugin)) { |
| 2159 | Melder_backgroundingcxx . . $ Melder_backgrounding. = true; |
| 2160 | try { |
| 2161 | praat_executeScript_noGUIcxx . . $ praat_executeScript_noGUI(36849bf2e291e39f). (& plugin, false); |
| 2162 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 2163 | Melder_flushErrorcxx . . $ Melder_flushError(6298c93241566110). (Melder_upperCaseAppNamecxx . . $ Melder_upperCaseAppName(1912f6684645c851).(), U": plugin ", & plugin, U" contains an error."); |
| 2164 | } |
| 2165 | Melder_backgroundingcxx . . $ Melder_backgrounding. = false; |
| 2166 | } |
| 2167 | } |
| 2168 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 2169 | Melder_clearErrorcxx . . $ Melder_clearError(49f6e7a06ebc5aa8). (); // in case folderNames_STRVEC() threw an error |
| 2170 | } |
| 2171 | } |
| 2172 | if (! MelderFolder_isNullcxx . . $ MelderFolder_isNull(f2f3cbeb84a71ab3). (Melder_preferencesFolder5cxx . . $ Melder_preferencesFolder5(3f0bf42ba8f9aa29).()) && ! praatPcxx . . $ praatP..ignorePluginscxx . . $ PraatP#ignorePlugins.) { |
| 2173 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"initialize plug-ins (", MelderFolder_peekPath (Melder_preferencesFolder5()), U")"); |
| 2174 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"locale is ", Melder_peek8to32_u (setlocale (LC_ALLcxx . . $ `<external>/3736975272097309885/locale.h:41:9`!, nullptr))); |
| 2175 | /* |
| 2176 | The Praat phase should remain praat_STARTING_UP, |
| 2177 | because any added commands must not be included in the buttons file. |
| 2178 | In plug-ins, pause windows should therefore be made modal. |
| 2179 | */ |
| 2180 | structMelderFilecxx . . $ structMelderFile# searchPattern { }; |
| 2181 | MelderFolder_getFilecxx . . $ MelderFolder_getFile(fcdc1f9d1818a0a1). (Melder_preferencesFolder5cxx . . $ Melder_preferencesFolder5(3f0bf42ba8f9aa29).(), U"plugin_*", & searchPattern); |
| 2182 | try { |
| 2183 | pluginFolderNames5 =cxx . . $ _autostringautovector#`operator=`(150f7ba7aac25b7e). folderNames_STRVECcxx . . $ folderNames_STRVEC(d3c03a92d990d008). (MelderFile_peekPathcxx . . $ MelderFile_peekPath(d9f043369fa9b55b). (& searchPattern)); |
| 2184 | for (integercxx . . $ integer# i = 1; i <= pluginFolderNames5.sizecxx . . $ _autostringautovector#size.; i ++) { |
| 2185 | if (NUMfindFirstcxx . . $ NUMfindFirst(5bcfdb87a5d5128). (pluginFolderNames7cxx . . $ _conststringvector#_conststringvector(93d9e701af42cb0d)..getcxx . . $ _autostringautovector#get(9d56076a9ef7dd02).(), pluginFolderNames5 [cxx . . $ _autostringautovector#`operator[]`(f191be2b65019068).i].getcxx . . $ _autostring#get(5a2a78a048fb49a8).()) != 0) { |
| 2186 | /* |
| 2187 | Ignore this plugin, because it has already been installed. |
| 2188 | */ |
| 2189 | Melder_casualcxx . . $ Melder_casual(6298c93241566110). (U"Plugin “", pluginFolderNames5 [cxx . . $ _autostringautovector#`operator[]`(f191be2b65019068).i].getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), U"” occurs both in “", |
| 2190 | MelderFolder_peekPathcxx . . $ MelderFolder_peekPath(fbe3b4f4d15c56ee). (Melder_preferencesFolder7cxx . . $ Melder_preferencesFolder7(3f0bf42ba8f9aa29).()), U"” and in “", MelderFolder_peekPathcxx . . $ MelderFolder_peekPath(fbe3b4f4d15c56ee). (Melder_preferencesFolder5cxx . . $ Melder_preferencesFolder5(3f0bf42ba8f9aa29).()), |
| 2191 | U"”; only the former is installed." |
| 2192 | ); |
| 2193 | } else { |
| 2194 | structMelderFoldercxx . . $ structMelderFolder# pluginFolder { }; |
| 2195 | structMelderFilecxx . . $ structMelderFile# plugin { }; |
| 2196 | MelderFolder_getSubfoldercxx . . $ MelderFolder_getSubfolder(a6a48bbd99ea6094). (Melder_preferencesFolder5cxx . . $ Melder_preferencesFolder5(3f0bf42ba8f9aa29).(), pluginFolderNames5 [cxx . . $ _autostringautovector#`operator[]`(f191be2b65019068).i].getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), & pluginFolder); |
| 2197 | MelderFolder_getFilecxx . . $ MelderFolder_getFile(fcdc1f9d1818a0a1). (& pluginFolder, U"setup.praat", & plugin); |
| 2198 | if (MelderFile_readablecxx . . $ MelderFile_readable(8f92cdf95b27d908). (& plugin)) { |
| 2199 | Melder_backgroundingcxx . . $ Melder_backgrounding. = true; |
| 2200 | try { |
| 2201 | praat_executeScript_noGUIcxx . . $ praat_executeScript_noGUI(36849bf2e291e39f). (& plugin, false); |
| 2202 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 2203 | Melder_flushErrorcxx . . $ Melder_flushError(6298c93241566110). (Melder_upperCaseAppNamecxx . . $ Melder_upperCaseAppName(1912f6684645c851).(), U": plugin ", & plugin, U" contains an error."); |
| 2204 | } |
| 2205 | Melder_backgroundingcxx . . $ Melder_backgrounding. = false; |
| 2206 | } |
| 2207 | } |
| 2208 | } |
| 2209 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 2210 | Melder_clearErrorcxx . . $ Melder_clearError(49f6e7a06ebc5aa8). (); // in case folderNames_STRVEC() threw an error |
| 2211 | } |
| 2212 | } |
| 2213 | |
| 2214 | /* |
| 2215 | Check the locale, to ensure identical behaviour on all computers. |
| 2216 | */ |
| 2217 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (str32equcxx . . $ `melder/melder_str32.h:122:9`! (Melder_double (1.5), U"1.5")); // check locale settings; because of the required file portability Praat cannot stand "1,5" |
| 2218 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (Melder_isHorizontalOrVerticalSpace (' ')); |
| 2219 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (Melder_isHorizontalOrVerticalSpace ('\r')); |
| 2220 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (Melder_isHorizontalOrVerticalSpace ('\n')); |
| 2221 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (Melder_isHorizontalOrVerticalSpace ('\t')); |
| 2222 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (Melder_isHorizontalOrVerticalSpace ('\f')); |
| 2223 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (Melder_isHorizontalOrVerticalSpace ('\v')); |
| 2224 | |
| 2225 | { |
| 2226 | double *a = nullptr; |
| 2227 | double *b = & a [0]; |
| 2228 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (! b); |
| 2229 | } |
| 2230 | |
| 2231 | /* |
| 2232 | According to ISO 30112, a non-breaking space is not a space. |
| 2233 | We do not agree, as long as spaces are assumed to be word breakers: |
| 2234 | non-breaking spaces are used to prevent line breaks, not to prevent word breaks. |
| 2235 | For instance, in English it's possible to insert a non-breaking space |
| 2236 | after "e.g." in "...take drastic measures, e.g. pose a ban on...", |
| 2237 | just because otherwise a line would end in a period that does not signal end of sentence; |
| 2238 | this use does not mean that "e.g." and "pose" aren't separate words. |
| 2239 | */ |
| 2240 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (Melder_isHorizontalOrVerticalSpace (UNICODE_NO_BREAK_SPACEcxx . . $ `kar/UnicodeData.h:320:9`!)); |
| 2241 | |
| 2242 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (Melder_isHorizontalOrVerticalSpace (UNICODE_OGHAM_SPACE_MARKcxx . . $ `kar/UnicodeData.h:10378:9`!)); // ISO 30112 |
| 2243 | |
| 2244 | /* |
| 2245 | According to ISO 30112, a Mongolian vowel separator is a space. |
| 2246 | However, this character is used to separate vowels *within* a word, |
| 2247 | so it should not be a word breaker. |
| 2248 | This means that as long as all spaces are assumed to be word breakers, |
| 2249 | this character cannot be a space. |
| 2250 | */ |
| 2251 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (! Melder_isHorizontalOrVerticalSpace (UNICODE_MONGOLIAN_VOWEL_SEPARATORcxx . . $ `kar/UnicodeData.h:11038:9`!)); |
| 2252 | |
| 2253 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (Melder_isHorizontalOrVerticalSpace (UNICODE_EN_QUADcxx . . $ `kar/UnicodeData.h:14722:9`!)); // ISO 30112 |
| 2254 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (Melder_isHorizontalOrVerticalSpace (UNICODE_EM_QUADcxx . . $ `kar/UnicodeData.h:14724:9`!)); // ISO 30112 |
| 2255 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (Melder_isHorizontalOrVerticalSpace (UNICODE_EN_SPACEcxx . . $ `kar/UnicodeData.h:14726:9`!)); // ISO 30112 |
| 2256 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (Melder_isHorizontalOrVerticalSpace (UNICODE_EM_SPACEcxx . . $ `kar/UnicodeData.h:14728:9`!)); // ISO 30112 |
| 2257 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (Melder_isHorizontalOrVerticalSpace (UNICODE_THREE_PER_EM_SPACEcxx . . $ `kar/UnicodeData.h:14730:9`!)); // ISO 30112 |
| 2258 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (Melder_isHorizontalOrVerticalSpace (UNICODE_FOUR_PER_EM_SPACEcxx . . $ `kar/UnicodeData.h:14732:9`!)); // ISO 30112 |
| 2259 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (Melder_isHorizontalOrVerticalSpace (UNICODE_SIX_PER_EM_SPACEcxx . . $ `kar/UnicodeData.h:14734:9`!)); // ISO 30112 |
| 2260 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (Melder_isHorizontalOrVerticalSpace (UNICODE_FIGURE_SPACEcxx . . $ `kar/UnicodeData.h:14736:9`!)); // questionable |
| 2261 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (Melder_isHorizontalOrVerticalSpace (UNICODE_PUNCTUATION_SPACEcxx . . $ `kar/UnicodeData.h:14738:9`!)); // ISO 30112 |
| 2262 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (Melder_isHorizontalOrVerticalSpace (UNICODE_THIN_SPACEcxx . . $ `kar/UnicodeData.h:14740:9`!)); // ISO 30112 |
| 2263 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (Melder_isHorizontalOrVerticalSpace (UNICODE_HAIR_SPACEcxx . . $ `kar/UnicodeData.h:14742:9`!)); // ISO 30112 |
| 2264 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (! Melder_isHorizontalOrVerticalSpace (UNICODE_ZERO_WIDTH_SPACEcxx . . $ `kar/UnicodeData.h:14744:9`!)); // questionable |
| 2265 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (! Melder_isHorizontalOrVerticalSpace (UNICODE_ZERO_WIDTH_NON_JOINERcxx . . $ `kar/UnicodeData.h:14746:9`!)); |
| 2266 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (! Melder_isHorizontalOrVerticalSpace (UNICODE_ZERO_WIDTH_JOINERcxx . . $ `kar/UnicodeData.h:14748:9`!)); |
| 2267 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (! Melder_isHorizontalOrVerticalSpace (UNICODE_ZERO_WIDTH_NO_BREAK_SPACEcxx . . $ `kar/UnicodeData.h:33338:9`!)); // this is the byte-order mark! |
| 2268 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (Melder_isHorizontalOrVerticalSpace (UNICODE_LINE_SEPARATORcxx . . $ `kar/UnicodeData.h:14802:9`!)); // ISO 30112 |
| 2269 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (Melder_isHorizontalOrVerticalSpace (UNICODE_PARAGRAPH_SEPARATORcxx . . $ `kar/UnicodeData.h:14804:9`!)); // ISO 30112 |
| 2270 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (Melder_isHorizontalOrVerticalSpace (UNICODE_NARROW_NO_BREAK_SPACEcxx . . $ `kar/UnicodeData.h:14816:9`!)); |
| 2271 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (! Melder_isHorizontalOrVerticalSpace (UNICODE_LEFT_TO_RIGHT_EMBEDDINGcxx . . $ `kar/UnicodeData.h:14806:9`!)); |
| 2272 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (! Melder_isHorizontalOrVerticalSpace (UNICODE_RIGHT_TO_LEFT_EMBEDDINGcxx . . $ `kar/UnicodeData.h:14808:9`!)); |
| 2273 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (! Melder_isHorizontalOrVerticalSpace (UNICODE_POP_DIRECTIONAL_FORMATTINGcxx . . $ `kar/UnicodeData.h:14810:9`!)); |
| 2274 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (! Melder_isHorizontalOrVerticalSpace (UNICODE_LEFT_TO_RIGHT_OVERRIDEcxx . . $ `kar/UnicodeData.h:14812:9`!)); |
| 2275 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (! Melder_isHorizontalOrVerticalSpace (UNICODE_RIGHT_TO_LEFT_OVERRIDEcxx . . $ `kar/UnicodeData.h:14814:9`!)); |
| 2276 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (Melder_isHorizontalOrVerticalSpace (UNICODE_MEDIUM_MATHEMATICAL_SPACEcxx . . $ `kar/UnicodeData.h:14912:9`!)); // ISO 30112 |
| 2277 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (! Melder_isHorizontalOrVerticalSpace (UNICODE_WORD_JOINERcxx . . $ `kar/UnicodeData.h:14914:9`!)); |
| 2278 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (! Melder_isHorizontalOrVerticalSpace (UNICODE_FUNCTION_APPLICATIONcxx . . $ `kar/UnicodeData.h:14916:9`!)); |
| 2279 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (! Melder_isHorizontalOrVerticalSpace (UNICODE_INVISIBLE_TIMEScxx . . $ `kar/UnicodeData.h:14918:9`!)); |
| 2280 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (! Melder_isHorizontalOrVerticalSpace (UNICODE_INVISIBLE_SEPARATORcxx . . $ `kar/UnicodeData.h:14920:9`!)); |
| 2281 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (! Melder_isHorizontalOrVerticalSpace (UNICODE_INHIBIT_SYMMETRIC_SWAPPINGcxx . . $ `kar/UnicodeData.h:14932:9`!)); |
| 2282 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (! Melder_isHorizontalOrVerticalSpace (UNICODE_ACTIVATE_SYMMETRIC_SWAPPINGcxx . . $ `kar/UnicodeData.h:14934:9`!)); |
| 2283 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (! Melder_isHorizontalOrVerticalSpace (UNICODE_INHIBIT_ARABIC_FORM_SHAPINGcxx . . $ `kar/UnicodeData.h:14936:9`!)); |
| 2284 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (! Melder_isHorizontalOrVerticalSpace (UNICODE_ACTIVATE_ARABIC_FORM_SHAPINGcxx . . $ `kar/UnicodeData.h:14938:9`!)); |
| 2285 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (! Melder_isHorizontalOrVerticalSpace (UNICODE_NATIONAL_DIGIT_SHAPEScxx . . $ `kar/UnicodeData.h:14940:9`!)); |
| 2286 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (! Melder_isHorizontalOrVerticalSpace (UNICODE_NOMINAL_DIGIT_SHAPEScxx . . $ `kar/UnicodeData.h:14942:9`!)); |
| 2287 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (Melder_isHorizontalOrVerticalSpace (UNICODE_IDEOGRAPHIC_SPACEcxx . . $ `kar/UnicodeData.h:22492:9`!)); // ISO 30112; occurs on Japanese computers |
| 2288 | |
| 2289 | { unsigned char dummy = 200; |
| 2290 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! ((int) dummy == 200); |
| 2291 | } |
| 2292 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (integer_abs (-1000) == integer (1000)); |
| 2293 | { int dummy = 200; |
| 2294 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! ((int) (signed char) dummy == -56); // bingeti8 relies on this |
| 2295 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! ((int) (unsigned char) dummy == 200); |
| 2296 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! ((double) dummy == 200.0); |
| 2297 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! ((double) (signed char) dummy == -56.0); |
| 2298 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! ((double) (unsigned char) dummy == 200.0); |
| 2299 | } |
| 2300 | { int64cxx . . $ int64# dummy = 200; |
| 2301 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! ((int) (signed char) dummy == -56); |
| 2302 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! ((int) (unsigned char) dummy == 200); |
| 2303 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! ((double) dummy == 200.0); |
| 2304 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! ((double) (signed char) dummy == -56.0); |
| 2305 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! ((double) (unsigned char) dummy == 200.0); |
| 2306 | } |
| 2307 | { uint16cxx . . $ uint16# dummy = 40000; |
| 2308 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! ((int) (int16) dummy == -25536); // bingeti16 relies on this |
| 2309 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! ((short) (int16) dummy == -25536); // bingete16 relies on this |
| 2310 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! ((integer) dummy == 40000); // Melder_integer relies on this |
| 2311 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! ((double) dummy == 40000.0); |
| 2312 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! ((double) (int16) dummy == -25536.0); |
| 2313 | } |
| 2314 | { unsigned int dummy = 40000; |
| 2315 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! ((int) (int16) dummy == -25536); |
| 2316 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! ((short) (int16) dummy == -25536); |
| 2317 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! ((integer) dummy == 40000); // Melder_integer relies on this |
| 2318 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! ((double) dummy == 40000.0); |
| 2319 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! ((double) (int16) dummy == -25536.0); |
| 2320 | } |
| 2321 | { |
| 2322 | int64cxx . . $ int64# dummy = 1000000000000; |
| 2323 | if (! str32equcxx . . $ `melder/melder_str32.h:122:9`! (Melder_integercxx . . $ Melder_integer(7b348ebc2004441d). (dummy), U"1000000000000")) |
| 2324 | Melder_crashcxx . . $ `melder/melder_error.h:98:9`! (U"The number 1000000000000 is mistakenly written on this machine as ", dummy, U"."); |
| 2325 | } |
| 2326 | { uint32cxx . . $ uint32# dummy = 0xffffffff; |
| 2327 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! ((int64) dummy == 4294967295LL); |
| 2328 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (str32equcxx . . $ `melder/melder_str32.h:122:9`! (Melder_integer (dummy), U"4294967295")); |
| 2329 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (double (dummy) == 4294967295.0); |
| 2330 | } |
| 2331 | { double dummy = 3000000000.0; |
| 2332 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! ((uint32) dummy == 3000000000); |
| 2333 | } |
| 2334 | { |
| 2335 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (Melder_length (U"hello") == 5); |
| 2336 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (str32ncmp (U"hellogoodbye", U"hellogee", 6) == 0); |
| 2337 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (str32ncmp (U"hellogoodbye", U"hellogee", 7) > 0); |
| 2338 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (str32str (U"hellogoodbye", U"ogo")); |
| 2339 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (! str32str (U"hellogoodbye", U"oygo")); |
| 2340 | } |
| 2341 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (isundef (undefined)); |
| 2342 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (isinf (1.0 / 0.0)); |
| 2343 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (isnan (0.0 / 0.0)); |
| 2344 | { |
| 2345 | double x = sqrtcxx . . $ sqrt(fee4f1d22bc8e617). (-10.0); |
| 2346 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (isundef (x)); |
| 2347 | x = NUMsqrt_ucxx . . $ NUMsqrt_u(447c67c6676f75c3). (-10.0); |
| 2348 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (isundef (x)); |
| 2349 | } |
| 2350 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (isdefined (0.0)); |
| 2351 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (isdefined (1e300)); |
| 2352 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (isundef (double (1e160 * 1e160))); |
| 2353 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (isundef (pow (10.0, 330))); |
| 2354 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (isundef (0.0 / 0.0)); |
| 2355 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (isundef (1.0 / 0.0)); |
| 2356 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (undefined != undefined); |
| 2357 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (undefined - undefined != 0.0); |
| 2358 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! ((1.0/0.0) == (1.0/0.0)); |
| 2359 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! ((1.0/0.0) - (1.0/0.0) != 0.0); |
| 2360 | { |
| 2361 | /* |
| 2362 | Assumptions made in abcio.cpp: |
| 2363 | `frexp()` returns an infinity if its argument is an infinity, |
| 2364 | and not-a-number if its argument is not-a-number. |
| 2365 | */ |
| 2366 | int exponent; |
| 2367 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (isundef (frexp (HUGE_VALcxx . . $ `<external>/11263917310783833665/math.h:48:10`!, & exponent))); |
| 2368 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (isundef (frexp (0.0/0.0, & exponent))); |
| 2369 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (isundef (frexp (undefined, & exponent))); |
| 2370 | /* |
| 2371 | The following relies on the facts that: |
| 2372 | - positive infinity is not less than 1.0 (because it is greater than 1.0) |
| 2373 | - NaN is not less than 1.0 (because it is not ordered) |
| 2374 | |
| 2375 | Note: we cannot replace `! (... < 1.0)` with `... >= 1.0`, |
| 2376 | because `! (NaN < 1.0)` is true but `NaN >= 1.0` is false. |
| 2377 | */ |
| 2378 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (! (frexp (HUGE_VALcxx . . $ `<external>/11263917310783833665/math.h:48:10`!, & exponent) < 1.0)); |
| 2379 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (! (frexp (0.0/0.0, & exponent) < 1.0)); |
| 2380 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (! (frexp (undefined, & exponent) < 1.0)); |
| 2381 | } |
| 2382 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (str32equcxx . . $ `melder/melder_str32.h:122:9`! (Melder_integer (1234567), U"1234567")); |
| 2383 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (str32equcxx . . $ `melder/melder_str32.h:122:9`! (Melder_integer (-1234567), U"-1234567")); |
| 2384 | MelderColourcxx . . $ MelderColour# notExplicitlyInitializedcxx . . $ MelderColour#MelderColour(49f6e7a06ebc5aa8).; |
| 2385 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (str32equcxx . . $ `melder/melder_str32.h:122:9`! (Melder_colour (notExplicitlyInitialized), U"{0,0,0}")); |
| 2386 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (str32equcxx . . $ `melder/melder_str32.h:122:9`! (Melder_colour (MelderColour (0.25, 0.50, 0.875)), U"{0.25,0.5,0.875}")); |
| 2387 | { |
| 2388 | VECcxx . . $ VEC# xncxx . . $ vector#vector(49f6e7a06ebc5aa8).; // "uninitialized", but initializes x.cells to nullptr and x.size to 0 |
| 2389 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (! xn.cells); |
| 2390 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (xn.size == 0); |
| 2391 | VECcxx . . $ VEC# xn2 = xn; // copy construction |
| 2392 | xn2 =cxx . . $ vector#`operator=`(958c14910af86093). xn; // copy assignment |
| 2393 | VECcxx . . $ VEC# xcxx . . $ vector#vector(49f6e7a06ebc5aa8). { }; |
| 2394 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (! x.cells); |
| 2395 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (x.size == 0); |
| 2396 | constVECcxx . . $ constVEC# xnccxx . . $ constvector#constvector(49f6e7a06ebc5aa8).; // zero-initialized |
| 2397 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (! xnc.cells); |
| 2398 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (xnc.size == 0); |
| 2399 | constVECcxx . . $ constVEC# xccxx . . $ constvector#constvector(49f6e7a06ebc5aa8). { }; |
| 2400 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (! xc.cells); |
| 2401 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (xc.size == 0); |
| 2402 | MATcxx . . $ MAT# yncxx . . $ matrix#matrix(49f6e7a06ebc5aa8).; |
| 2403 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (! yn.cells); |
| 2404 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (yn.nrow == 0); |
| 2405 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (yn.ncol == 0); |
| 2406 | MATcxx . . $ MAT# ycxx . . $ matrix#matrix(49f6e7a06ebc5aa8). { }; |
| 2407 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (! y.cells); |
| 2408 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (y.nrow == 0); |
| 2409 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (y.ncol == 0); |
| 2410 | //autoMAT z {y.cells,y.nrow,y.ncol}; // "No matching constructor for initialization of autoMAT" (2021-04-05) |
| 2411 | autoMATcxx . . $ autoMAT# a = autoMATcxx . . $ automatrix#automatrix(49f6e7a06ebc5aa8). { }; |
| 2412 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (! a.cells); |
| 2413 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (a.nrow == 0); |
| 2414 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (a.ncol == 0); |
| 2415 | //a = z.move(); |
| 2416 | //double q [11]; |
| 2417 | //autoVEC s { & q [1], 10 }; // "No matching constructor for initialization of autoVEC" (2021-04-05) |
| 2418 | //autoVEC b { x }; // "No matching constructor for initialization of autoVEC" (2021-04-05) |
| 2419 | //autoVEC c = x; // "No viable conversion from VEC to autoVEC" (2021-04-05) |
| 2420 | double aa [] = { 3.14, 2.717999999999999971578290569595992565155029296875 }; // the second number is 765048986699563 / 2^48 |
| 2421 | VECcxx . . $ VEC# x3cxx . . $ vector#vector(3aadefc30ed88664). (aa, 2); // initializes x3 to 2 values from a base-0 array |
| 2422 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (x3 [2] == 2.717999999999999971578290569595992565155029296875); |
| 2423 | autoVECcxx . . $ autoVEC# x4 = {cxx . . $ autovector#autovector(8de98f561e977378). 3.14, 2.717999999999999971578290569595992565155029296875 }; |
| 2424 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (x4 [2] == 2.717999999999999971578290569595992565155029296875); |
| 2425 | } |
| 2426 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (Melder_iroundUpToPowerOfTwo (-10) == 1); |
| 2427 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (Melder_iroundUpToPowerOfTwo (-1) == 1); |
| 2428 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (Melder_iroundUpToPowerOfTwo (0) == 1); |
| 2429 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (Melder_iroundUpToPowerOfTwo (1) == 1); |
| 2430 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (Melder_iroundUpToPowerOfTwo (2) == 2); |
| 2431 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (Melder_iroundUpToPowerOfTwo (3) == 4); |
| 2432 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (Melder_iroundUpToPowerOfTwo (4) == 4); |
| 2433 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (Melder_iroundUpToPowerOfTwo (5) == 8); |
| 2434 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (Melder_iroundUpToPowerOfTwo (6) == 8); |
| 2435 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (Melder_iroundUpToPowerOfTwo (7) == 8); |
| 2436 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (Melder_iroundUpToPowerOfTwo (8) == 8); |
| 2437 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (Melder_iroundUpToPowerOfTwo (9) == 16); |
| 2438 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (Melder_iroundUpToPowerOfTwo (44100) == 65536); |
| 2439 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (Melder_iroundUpToPowerOfTwo (131071) == 131072); |
| 2440 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (Melder_iroundUpToPowerOfTwo (131072) == 131072); |
| 2441 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (Melder_iroundUpToPowerOfTwo (131073) == 262144); |
| 2442 | if constexpr (sizeof (integercxx . . $ integer#) == 4) { |
| 2443 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (Melder_iroundUpToPowerOfTwo (1073741823) == 1073741824); // 2^30 - 1 |
| 2444 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (Melder_iroundUpToPowerOfTwo (1073741824) == 1073741824); // 2^30 |
| 2445 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (Melder_iroundUpToPowerOfTwo (1073741825) == 0); // 2^30 + 1 |
| 2446 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (Melder_iroundUpToPowerOfTwo (2147483647) == 0); // 2^31 - 1, i.e. INTEGER_MAX |
| 2447 | } else { |
| 2448 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (Melder_iroundUpToPowerOfTwo (4611686018427387903LL) == 4611686018427387904LL); // 2^62 - 1 |
| 2449 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (Melder_iroundUpToPowerOfTwo (4611686018427387904LL) == 4611686018427387904LL); // 2^62 |
| 2450 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (Melder_iroundUpToPowerOfTwo (4611686018427387905LL) == 0); // 2^62 + 1 |
| 2451 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (Melder_iroundUpToPowerOfTwo (9223372036854775807LL) == 0); // 2^63 - 1, i.e. INTEGER_MAX |
| 2452 | } |
| 2453 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (Melder_iroundUpToPowerOfTwo (4) == 4); |
| 2454 | { |
| 2455 | autoMATcxx . . $ autoMAT# mat = {cxx . . $ automatrix#automatrix(6181ce3ac90ba4b6). { 10, 20, 30, 40 }, { 60, 70, 80, 90 }, { 170, 180, 190, -300 } }; |
| 2456 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (mat [1] [1] == 10.0); |
| 2457 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (mat [1] [4] == 40.0); |
| 2458 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (mat [2] [3] == 80.0); |
| 2459 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (mat [3] [1] == 170.0); |
| 2460 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (mat [3] [4] == -300.0); |
| 2461 | } |
| 2462 | static_assert (sizeof (float) == 4, |
| 2463 | "sizeof(float) should be 4"); |
| 2464 | static_assert (sizeof (double) == 8, |
| 2465 | "sizeof(double) should be 8"); |
| 2466 | static_assert (sizeof (longdoublecxx . . $ longdouble#) >= 8, |
| 2467 | "sizeof(longdouble) should be at least 8"); // this can be 8, 12 or 16 |
| 2468 | static_assert (sizeof (integercxx . . $ integer#) == sizeof (void *), |
| 2469 | "sizeof(integer) should equal the size of a pointer"); |
| 2470 | static_assert (sizeof (off_t) >= 8, |
| 2471 | "sizeof(off_t) is less than 8. Compile Praat with -D_FILE_OFFSET_BITS=64."); |
| 2472 | |
| 2473 | /* |
| 2474 | Some libraries expect the definition of endian information. |
| 2475 | Check here at compile time that these are #defined, |
| 2476 | and check here at runtime that they have the correct value. |
| 2477 | */ |
| 2478 | #if ! defined (__BYTE_ORDER__cxx . . $ `<built-in>:113:9`!) || ! defined (__ORDER_BIG_ENDIAN__cxx . . $ `<built-in>:111:9`!) || ! defined (__ORDER_LITTLE_ENDIAN__cxx . . $ `<built-in>:110:9`!) |
| 2479 | #if defined (_MSC_VER) |
| 2480 | #error On MSVC, define __ORDER_BIG_ENDIAN__=4321, __ORDER_LITTLE_ENDIAN__=1234, and __BYTE_ORDER__=1234 |
| 2481 | #else |
| 2482 | #error __BYTE_ORDER__, __ORDER_BIG_ENDIAN__ and __ORDER_LITTLE_ENDIAN__ should be #defined |
| 2483 | #endif |
| 2484 | #endif |
| 2485 | if (Melder_integersAreBigEndiancxx . . $ Melder_integersAreBigEndian(c9857a73d68e59ba).()) |
| 2486 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (__BYTE_ORDER__cxx . . $ `<built-in>:113:9`! == __ORDER_BIG_ENDIAN__cxx . . $ `<built-in>:111:9`!); |
| 2487 | else |
| 2488 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (__BYTE_ORDER__cxx . . $ `<built-in>:113:9`! == __ORDER_LITTLE_ENDIAN__cxx . . $ `<built-in>:110:9`!); |
| 2489 | |
| 2490 | /* |
| 2491 | The type "integer" is defined as intptr_t, analogously to uinteger as uintptr_t |
| 2492 | (last checked 2024-08-18). |
| 2493 | However, the usual definition of an integer type that has 32 bits on 32-bit platforms |
| 2494 | and 64 bits on 64-bit platforms would be ptrdiff_t. |
| 2495 | Check that these definitions are the same. |
| 2496 | */ |
| 2497 | static_assert (sizeof (integercxx . . $ integer#) == sizeof (ptrdiff_t), |
| 2498 | "sizeof(integer) should equal sizeof(ptrdiff_t)"); |
| 2499 | /* |
| 2500 | The format %td is designed for ptrdiff_t, and should therefore also work for our "integer" type, |
| 2501 | as "integer" has been defined as intptr_t, which we just checked is equivalent to ptrdiff_t. |
| 2502 | Check that %td indeed works correctly for "integer". |
| 2503 | */ |
| 2504 | { |
| 2505 | integercxx . . $ integer# n1, n2; |
| 2506 | sscanf ("456789 -12345", "%td%td", & n1, & n2); |
| 2507 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (n1 == 456789 && n2 == -12345); |
| 2508 | } |
| 2509 | |
| 2510 | /* |
| 2511 | Check some assumptions about non-argument-evaluation during void tracing, |
| 2512 | and about the order of argument evaluation. |
| 2513 | */ |
| 2514 | { |
| 2515 | //TRACE |
| 2516 | int i = 0; |
| 2517 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"digits 1 to 9: ", ++ i, ++ i, ++ i, ++ i, ++ i, ++ i, ++ i, ++ i, ++ i); |
| 2518 | if (Melder_isTracingLocallycxx . . $ Melder_isTracingLocally. || Melder_isTracingGloballycxx . . $ Melder_isTracingGlobally.) |
| 2519 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (i == 9); |
| 2520 | else |
| 2521 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (i == 0); |
| 2522 | i = 0; |
| 2523 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"digits 1 to 9: ", i ++, i ++, i ++, i ++, i ++, i ++, i ++, i ++, i ++); |
| 2524 | if (Melder_isTracingLocallycxx . . $ Melder_isTracingLocally. || Melder_isTracingGloballycxx . . $ Melder_isTracingGlobally.) |
| 2525 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (i == 9); |
| 2526 | else |
| 2527 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (i == 0); |
| 2528 | char buffer [40]; |
| 2529 | i = 0; |
| 2530 | snprintf (buffer,40, "digits 1 to 9: %d%d%d%d%d%d%d%d%d", ++ i, ++ i, ++ i, ++ i, ++ i, ++ i, ++ i, ++ i, ++ i); |
| 2531 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (i == 9); |
| 2532 | tracecxx . . $ `melder/melder_debug.h:60:10`! (Melder_peek8to32_u (buffer)); |
| 2533 | i = 0; |
| 2534 | snprintf (buffer,40, "digits 1 to 9: %d%d%d%d%d%d%d%d%d", i ++, i ++, i ++, i ++, i ++, i ++, i ++, i ++, i ++); |
| 2535 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (i == 9); |
| 2536 | tracecxx . . $ `melder/melder_debug.h:60:10`! (Melder_peek8to32_u (buffer)); |
| 2537 | /* |
| 2538 | Results: trace and snprintf yield the same sequence as each other, on all systems we tested (last checked 2024-08-18) |
| 2539 | Pre-incrementing gives: |
| 2540 | 123456789 on Xcode, Msys Clang ARM64/Intel64/Intel32 |
| 2541 | preliminary generalization: all Clang |
| 2542 | 999999999 on Msys Gcc Intel64/Intel32, Cygwin Gcc Intel64/Intel32, Orb Ubuntu Gcc ARM64/Intel64, Raspberry Pi Gcc ARMv7, LinuxONE Gcc s390x |
| 2543 | preliminary generalization: all Gcc |
| 2544 | Post-incrementing gives: |
| 2545 | 012345678 on Xcode, Msys Clang ARM64/Intel64/Intel32, Orb Ubuntu Gcc ARM64, Raspberry Pi Gcc ARMv7, LinuxONE Gcc s390x |
| 2546 | preliminary generalization: all Clang, as well as all Gcc on anything else than Intel64/Intel32 |
| 2547 | 876543210 on Msys Gcc Intel64/32, Cygwin Gcc Intel64/Intel32, Orb Ubuntu Gcc Intel64 |
| 2548 | preliminary generalization: all Gcc on Intel64/Intel32 |
| 2549 | 000000000 on none yet |
| 2550 | A pleasing degree of variation! |
| 2551 | It's good to know that the order doesn't depend on whether the function is implemented in a recursive template (as trace) |
| 2552 | or in the C library (as snprintf). For instance, this means that even though the recursive-template implementation |
| 2553 | may look as though it evaluates from left to right, it doesn't necessarily do that. |
| 2554 | The bottom line is that for a given variable you can use only a single pre-increment or a single post-increment |
| 2555 | in any function call, even for the recursive templates of our own devising. |
| 2556 | */ |
| 2557 | } |
| 2558 | |
| 2559 | if (Melder_batchcxx . . $ Melder_batch.) { |
| 2560 | if (thePraatStandAloneScriptTextcxx . . $ thePraatStandAloneScriptText.) { |
| 2561 | try { |
| 2562 | praat_executeScriptFromTextcxx . . $ praat_executeScriptFromText(ff00d524ab0355ec). (thePraatStandAloneScriptTextcxx . . $ thePraatStandAloneScriptText.); // executed with full trust, because *we* made it |
| 2563 | praat_exitcxx . . $ praat_exit(d4f767463ce0a6b3). (0); |
| 2564 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 2565 | Melder_flushErrorcxx . . $ Melder_flushError(6298c93241566110). (Melder_upperCaseAppNamecxx . . $ Melder_upperCaseAppName(1912f6684645c851).(), U": stand-alone script session interrupted."); |
| 2566 | praat_exitcxx . . $ praat_exit(d4f767463ce0a6b3). (-1); |
| 2567 | } |
| 2568 | } else if (praatPcxx . . $ praatP..hasCommandLineInputcxx . . $ PraatP#hasCommandLineInput.) { |
| 2569 | try { |
| 2570 | praat_executeCommandFromStandardInputcxx . . $ praat_executeCommandFromStandardInput(ff00d524ab0355ec). (Melder_upperCaseAppNamecxx . . $ Melder_upperCaseAppName(1912f6684645c851).()); |
| 2571 | praat_exitcxx . . $ praat_exit(d4f767463ce0a6b3). (0); |
| 2572 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 2573 | Melder_flushErrorcxx . . $ Melder_flushError(6298c93241566110). (Melder_upperCaseAppNamecxx . . $ Melder_upperCaseAppName(1912f6684645c851).(), U": command line session interrupted."); |
| 2574 | praat_exitcxx . . $ praat_exit(d4f767463ce0a6b3). (-1); |
| 2575 | } |
| 2576 | } else { |
| 2577 | try { |
| 2578 | #ifdef _WIN32 |
| 2579 | /* |
| 2580 | Our WinMain app cannot be a true console app when run from the Console. |
| 2581 | |
| 2582 | The following is what we expect from a console app: |
| 2583 | 1. After you enter `Praat.exe myScript.praat` into the Console, |
| 2584 | the Console should go to the next line, but show nothing else. |
| 2585 | 2. Any console output (i.e. output to stdout and stderr) should appear |
| 2586 | on this line and the next lines. |
| 2587 | 3. When Praat finishes, the Console should show the new prompt, |
| 2588 | like `C:\Users\Me\myFolder>`, on a new line. |
| 2589 | |
| 2590 | Instead, if we do nothing special here, Praat will do the following in the Console: |
| 2591 | 1. After you enter `Praat.exe myScript.praat`, the Console will immediately |
| 2592 | present the `C:\Users\Me\myFolder>` prompt again. We know of no way |
| 2593 | to change this behaviour, short of compiling Praat as a console app. |
| 2594 | 2. Any console output (i.e. output to stdout and stderr) will appear |
| 2595 | immediately after the `C:\Users\Me\myFolder>` prompt. |
| 2596 | 3. When Praat finishes, the Console will show no new prompt, because |
| 2597 | it has already shown a prompt (too early). A new prompt will appear |
| 2598 | only once you type the Enter key. |
| 2599 | |
| 2600 | The most important problem to repair is 3, because otherwise it will look |
| 2601 | as if Praat has not finished. So in Chunk 2 we fake an Enter. |
| 2602 | |
| 2603 | Problem 2 is repaired in Chunk 1 by sending a line to stderr (not stdout, |
| 2604 | because the line break should not end up in a file if redirected). |
| 2605 | The line that is sent should not be empty, because an empty line would suggest |
| 2606 | that Praat has finished, so we send a visible comment with hashes ("##########"). |
| 2607 | |
| 2608 | Our output will still look different from a real console app because of the extra |
| 2609 | prompt at the beginning (prepended to our comment) and perhaps the extra |
| 2610 | empty line that will appear now at the end of the output. |
| 2611 | (last checked 2022-10-12) |
| 2612 | |
| 2613 | Chunk 1 (sending a comment to stderr): |
| 2614 | */ |
| 2615 | HWND optionalConsoleWindowHandle = GetConsoleWindow (); |
| 2616 | if (optionalConsoleWindowHandle) |
| 2617 | Melder_casual (U" ########## Running Praat script ", theCurrentPraatApplication -> batchName.string); |
| 2618 | #endif |
| 2619 | praat_executeScriptFromCommandLinecxx . . $ praat_executeScriptFromCommandLine(f3d464eb7bbd4ab6). (theCurrentPraatApplicationcxx . . $ theCurrentPraatApplication. -> batchNamecxx . . $ structPraatApplication#batchName..stringcxx . . $ MelderString#string., |
| 2620 | praatPcxx . . $ praatP..argccxx . . $ PraatP#argc. - praatPcxx . . $ praatP..argumentNumbercxx . . $ PraatP#argumentNumber., & praatPcxx . . $ praatP..argvcxx . . $ PraatP#argv. [praatPcxx . . $ praatP..argumentNumbercxx . . $ PraatP#argumentNumber.], praatPcxx . . $ praatP..fullTrustcxx . . $ PraatP#fullTrust.); |
| 2621 | #ifdef _WIN32 |
| 2622 | /* |
| 2623 | Chunk 2 (faking an Enter): |
| 2624 | */ |
| 2625 | if (optionalConsoleWindowHandle) |
| 2626 | PostMessage (optionalConsoleWindowHandle, WM_KEYDOWN, VK_RETURN, 0); |
| 2627 | |
| 2628 | FreeConsole (); // this may not do anything? (last checked 2022-10-12) |
| 2629 | #endif |
| 2630 | praat_exitcxx . . $ praat_exit(d4f767463ce0a6b3). (0); |
| 2631 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 2632 | Melder_flushErrorcxx . . $ Melder_flushError(6298c93241566110). (Melder_upperCaseAppNamecxx . . $ Melder_upperCaseAppName(1912f6684645c851).(), U": script command <<", |
| 2633 | theCurrentPraatApplicationcxx . . $ theCurrentPraatApplication. -> batchNamecxx . . $ structPraatApplication#batchName..stringcxx . . $ MelderString#string., U">> not completed."); |
| 2634 | praat_exitcxx . . $ praat_exit(d4f767463ce0a6b3). (-1); |
| 2635 | } |
| 2636 | } |
| 2637 | } else /* GUI */ { |
| 2638 | if (! praatPcxx . . $ praatP..ignorePreferenceFilescxx . . $ PraatP#ignorePreferenceFiles.) { |
| 2639 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"reading the added script buttons"); |
| 2640 | /* Each line separately: every error should be ignored. |
| 2641 | */ |
| 2642 | praatPcxx . . $ praatP..phasecxx . . $ PraatP#phase. = praat_READING_BUTTONScxx . . $ `sys/praatP.h:95:9`!; |
| 2643 | {// scope |
| 2644 | autostring32cxx . . $ autostring32# buttonscxx . . $ _autostring#_autostring(49f6e7a06ebc5aa8).; |
| 2645 | try { |
| 2646 | if (MelderFile_readablecxx . . $ MelderFile_readable(8f92cdf95b27d908). (& buttonsFile7cxx . . $ buttonsFile7.)) |
| 2647 | buttons =cxx . . $ _autostring#`operator=`(f562943cbc4bcf37). MelderFile_readTextcxx . . $ MelderFile_readText(2312d39ae70aea26). (& buttonsFile7cxx . . $ buttonsFile7.); // first choice |
| 2648 | else |
| 2649 | buttons =cxx . . $ _autostring#`operator=`(f562943cbc4bcf37). MelderFile_readTextcxx . . $ MelderFile_readText(2312d39ae70aea26). (& buttonsFile5cxx . . $ buttonsFile5.); // second choice; note: this will be converted to buttonsFile7 upon exit |
| 2650 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 2651 | Melder_clearErrorcxx . . $ Melder_clearError(49f6e7a06ebc5aa8). (); // ignore if a buttons file doesn't exist |
| 2652 | } |
| 2653 | if (buttons) { |
| 2654 | char32cxx . . $ char32# *line = buttons.getcxx . . $ _autostring#get(5a2a78a048fb49a8).(); |
| 2655 | for (;;) { |
| 2656 | char32cxx . . $ char32# *newline = str32chrcxx . . $ str32chr(328a9ede0fba853a). (line, U'\n'); |
| 2657 | if (newline) *newline = U'\0'; |
| 2658 | try { |
| 2659 | (void) praat_executeCommandcxx . . $ praat_executeCommand(fa53797037260a84). (nullptr, line); // should contain no cases of "nocheck" |
| 2660 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 2661 | Melder_clearErrorcxx . . $ Melder_clearError(49f6e7a06ebc5aa8). (); // ignore this line, but not necessarily the next |
| 2662 | } |
| 2663 | if (! newline) |
| 2664 | break; |
| 2665 | line = newline + 1; |
| 2666 | } |
| 2667 | } |
| 2668 | } |
| 2669 | } |
| 2670 | |
| 2671 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"sorting the commands"); |
| 2672 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"locale is ", Melder_peek8to32_u (setlocale (LC_ALLcxx . . $ `<external>/3736975272097309885/locale.h:41:9`!, nullptr))); |
| 2673 | praat_sortMenuCommandscxx . . $ praat_sortMenuCommands(49f6e7a06ebc5aa8). (); |
| 2674 | praat_sortActionscxx . . $ praat_sortActions(49f6e7a06ebc5aa8). (); |
| 2675 | |
| 2676 | praatPcxx . . $ praatP..phasecxx . . $ PraatP#phase. = praat_HANDLING_EVENTScxx . . $ `sys/praatP.h:96:9`!; |
| 2677 | |
| 2678 | if (praatPcxx . . $ praatP..userWantsToOpencxx . . $ PraatP#userWantsToOpen.) { |
| 2679 | /* |
| 2680 | praat --new-open [OPTION]... FILE-NAME... |
| 2681 | praat --open [OPTION]... FILE-NAME... (if not yet running) |
| 2682 | */ |
| 2683 | for (; praatPcxx . . $ praatP..argumentNumbercxx . . $ PraatP#argumentNumber. < praatPcxx . . $ praatP..argccxx . . $ PraatP#argc.; praatPcxx . . $ praatP..argumentNumbercxx . . $ PraatP#argumentNumber. ++) { |
| 2684 | autostring32cxx . . $ autostring32# text = Melder_dupcxx . . $ Melder_dup(87bf156b1f548402). (Melder_catcxx . . $ Melder_cat(7fbf27f4d367f442). (U"Read from file: ~", |
| 2685 | Melder_peek8to32_u (praatPcxx . . $ praatP..argvcxx . . $ PraatP#argv. [praatPcxx . . $ praatP..argumentNumbercxx . . $ PraatP#argumentNumber.]))); |
| 2686 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"Argument ", praatP.argumentNumber, U": <<", text.get(), U">>"); |
| 2687 | try { |
| 2688 | praat_executeScriptFromTextcxx . . $ praat_executeScriptFromText(ff00d524ab0355ec). (text.getcxx . . $ _autostring#get(5a2a78a048fb49a8).()); // executed with full trust, because we just constructed the whole script |
| 2689 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 2690 | Melder_flushErrorcxx . . $ Melder_flushError(49f6e7a06ebc5aa8). (); |
| 2691 | } |
| 2692 | } |
| 2693 | } else if (praatPcxx . . $ praatP..userWantsToSendcxx . . $ PraatP#userWantsToSend.) { |
| 2694 | /* |
| 2695 | praat --new-send [OPTION]... SCRIPT-FILE-NAME [SCRIPT-ARGUMENT]... |
| 2696 | praat --send [OPTION]... SCRIPT-FILE-NAME [SCRIPT-ARGUMENT]... (if not yet running) |
| 2697 | */ |
| 2698 | autoPraatBackgroundcxx . . $ autoPraatBackground# backgroundcxx . . $ autoPraatBackground#autoPraatBackground(49f6e7a06ebc5aa8).; // to e.g. make audio synchronous |
| 2699 | try { |
| 2700 | praat_executeScriptFromCommandLinecxx . . $ praat_executeScriptFromCommandLine(f3d464eb7bbd4ab6). (theCurrentPraatApplicationcxx . . $ theCurrentPraatApplication. -> batchNamecxx . . $ structPraatApplication#batchName..stringcxx . . $ MelderString#string., |
| 2701 | praatPcxx . . $ praatP..argccxx . . $ PraatP#argc. - praatPcxx . . $ praatP..argumentNumbercxx . . $ PraatP#argumentNumber., & praatPcxx . . $ praatP..argvcxx . . $ PraatP#argv. [praatPcxx . . $ praatP..argumentNumbercxx . . $ PraatP#argumentNumber.], praatPcxx . . $ praatP..fullTrustcxx . . $ PraatP#fullTrust.); |
| 2702 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 2703 | Melder_flushErrorcxx . . $ Melder_flushError(49f6e7a06ebc5aa8). (); |
| 2704 | } |
| 2705 | } else if (praatPcxx . . $ praatP..userWantsToSendOrFormcxx . . $ PraatP#userWantsToSendOrForm.) { |
| 2706 | /* |
| 2707 | praat --new-send-or-form [OPTION]... SCRIPT-FILE-NAME |
| 2708 | praat --send-or-form [OPTION]... SCRIPT-FILE-NAME (if not yet running) |
| 2709 | */ |
| 2710 | autoPraatBackgroundcxx . . $ autoPraatBackground# backgroundcxx . . $ autoPraatBackground#autoPraatBackground(49f6e7a06ebc5aa8).; // to e.g. make audio synchronous |
| 2711 | try { |
| 2712 | praat_runScriptWithFormcxx . . $ praat_runScriptWithForm(7004b68cc6c23ea2). (theCurrentPraatApplicationcxx . . $ theCurrentPraatApplication. -> batchNamecxx . . $ structPraatApplication#batchName..stringcxx . . $ MelderString#string., praatPcxx . . $ praatP..fullTrustcxx . . $ PraatP#fullTrust.); |
| 2713 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 2714 | Melder_flushErrorcxx . . $ Melder_flushError(49f6e7a06ebc5aa8). (); |
| 2715 | } |
| 2716 | } |
| 2717 | //TRACE |
| 2718 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"Before main event loop: ", Melder_stopwatch ()); |
| 2719 | |
| 2720 | #if gtkcxx . . $ `sys/Gui.h:33:10`! |
| 2721 | //gtk_widget_add_events (G_OBJECT (theCurrentPraatApplication -> topShell), GDK_ALL_EVENTS_MASK); |
| 2722 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"install GTK key snooper"); |
| 2723 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"locale is ", Melder_peek8to32_u (setlocale (LC_ALLcxx . . $ `<external>/3736975272097309885/locale.h:41:9`!, nullptr))); |
| 2724 | //g_signal_newv ("SENDPRAAT", G_TYPE_FROM_CLASS (gobject_class), G_SIGNAL_RUN_LAST, NULL, NULL, NULL, NULL, G_TYPE_NONE, 0, NULL); |
| 2725 | g_signal_connectcxx . . $ `<external>/15952772511652638895/gsignal.h:548:9`! (G_OBJECTcxx . . $ `<external>/1341695927569185362/gobject.h:54:9`! (theCurrentPraatApplication -> topShell -> d_gtkWindow), "property-notify-event", |
| 2726 | G_CALLBACKcxx . . $ `<external>/16473872192229286895/gclosure.h:73:9`! (cb_userMessage), nullptr); |
| 2727 | signal (SIGUSR1cxx . . $ `<external>/1457673850468744829/signum-arch.h:49:9`!, cb_sigusr1cxx . . $ cb_sigusr1(d4f767463ce0a6b3).); |
| 2728 | gtk_key_snooper_install (theKeySnoopercxx . . $ theKeySnooper(8197e4767abdb7c6)., 0); |
| 2729 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"start the GTK event loop"); |
| 2730 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"locale is ", Melder_peek8to32_u (setlocale (LC_ALLcxx . . $ `<external>/3736975272097309885/locale.h:41:9`!, nullptr))); |
| 2731 | gtk_main (); |
| 2732 | #elif motif |
| 2733 | for (;;) { |
| 2734 | XEvent event; |
| 2735 | GuiNextEvent (& event); |
| 2736 | XtDispatchEvent (& event); |
| 2737 | } |
| 2738 | #elif cocoa |
| 2739 | [NSApp run]; |
| 2740 | #endif |
| 2741 | } |
| 2742 | } |
| 2743 | |
| 2744 | /* End of file praat.cpp */ |