| 1 | /* praat_script.cpp |
| 2 | * |
| 3 | * Copyright (C) 1993-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 "praatP.h"cxx . . $ `<file>/sys/praatP.h`/ |
| 20 | #include "praat_script.h"cxx . . $ `<file>/sys/praat_script.h`/ |
| 21 | #include "UiPause.h"cxx . . $ `<file>/sys/UiPause.h`/ |
| 22 | #include "DemoEditor.h"cxx . . $ `<file>/sys/DemoEditor.h`/ |
| 23 | |
| 24 | static integercxx . . $ integer# praat_findObjectFromStringcxx . . $ praat_findObjectFromString(df2c8148a0293fef). (Interpretercxx . . $ Interpreter# interpreter, conststring32cxx . . $ conststring32# string) { |
| 25 | try { |
| 26 | integercxx . . $ integer# IOBJECT; |
| 27 | while (*string == U' ') |
| 28 | string ++; |
| 29 | if (*string >= U'A' && *string <= U'Z') { |
| 30 | /* |
| 31 | Find the object by its name. |
| 32 | */ |
| 33 | static MelderStringcxx . . $ MelderString# buffer; |
| 34 | MelderString_copycxx . . $ MelderString_copy(65be51a793e0ff96). (& buffer, string); |
| 35 | char32cxx . . $ char32# *space = str32chrcxx . . $ str32chr(328a9ede0fba853a). (buffer.stringcxx . . $ MelderString#string., U' '); |
| 36 | if (! space) |
| 37 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Missing space in name."); |
| 38 | *space = U'\0'; |
| 39 | char32cxx . . $ char32# *className = & buffer.stringcxx . . $ MelderString#string. [0], *givenName = space + 1; |
| 40 | WHERE_DOWNcxx . . $ `sys/praat.h:199:9`! (1) { |
| 41 | Daatacxx . . $ Daata# object = (Daatacxx . . $ Daata#) OBJECTcxx . . $ `sys/praat.h:203:9`!; |
| 42 | if (str32equcxx . . $ `melder/melder_str32.h:122:9`! (className, Thing_classNamecxx . . $ Thing_className(fbb3dc34e3ef688d). (OBJECTcxx . . $ `sys/praat.h:203:9`!)) && str32equcxx . . $ `melder/melder_str32.h:122:9`! (givenName, object -> namecxx . . $ structThing#name..getcxx . . $ _autostring#get(5a2a78a048fb49a8).())) |
| 43 | return IOBJECT; |
| 44 | } |
| 45 | /* |
| 46 | No object with that name. Perhaps the class name was wrong? |
| 47 | */ |
| 48 | ClassInfocxx . . $ ClassInfo# klas = Thing_classFromClassNamecxx . . $ Thing_classFromClassName(8643cf72d5cb42e3). (className, nullptr); |
| 49 | WHERE_DOWNcxx . . $ `sys/praat.h:199:9`! (1) { |
| 50 | Daatacxx . . $ Daata# object = (Daatacxx . . $ Daata#) OBJECTcxx . . $ `sys/praat.h:203:9`!; |
| 51 | if (str32equcxx . . $ `melder/melder_str32.h:122:9`! (klas -> classNamecxx . . $ structClassInfo#className., Thing_classNamecxx . . $ Thing_className(fbb3dc34e3ef688d). (OBJECTcxx . . $ `sys/praat.h:203:9`!)) && str32equcxx . . $ `melder/melder_str32.h:122:9`! (givenName, object -> namecxx . . $ structThing#name..getcxx . . $ _autostring#get(5a2a78a048fb49a8).())) |
| 52 | return IOBJECT; |
| 53 | } |
| 54 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"No object with that name."); |
| 55 | } else { |
| 56 | /* |
| 57 | Find the object by its ID. |
| 58 | */ |
| 59 | double value; |
| 60 | Interpreter_numericExpressioncxx . . $ Interpreter_numericExpression(8639512facf48b76). (interpreter, string, & value); |
| 61 | const integercxx . . $ integer# id = (integercxx . . $ integer#) value; // SMELL: rounding down |
| 62 | WHEREcxx . . $ `sys/praat.h:198:9`! (IDcxx . . $ `sys/praat.h:206:9`! == id) |
| 63 | return IOBJECT; |
| 64 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"No object with number ", id, U"."); |
| 65 | } |
| 66 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 67 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Object \"", string, U"\" does not exist."); |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | Editorcxx . . $ Editor# praat_findEditorFromStringcxx . . $ praat_findEditorFromString(2ddda295cd13730e). (conststring32cxx . . $ conststring32# string) { |
| 72 | integercxx . . $ integer# IOBJECT; |
| 73 | while (*string == U' ') |
| 74 | string ++; |
| 75 | if (*string >= U'A' && *string <= U'Z') { |
| 76 | WHERE_DOWNcxx . . $ `sys/praat.h:199:9`! (1) { |
| 77 | for (int ieditor = 0; ieditor < praat_MAXNUM_EDITORScxx . . $ `sys/praat.h:121:9`!; ieditor ++) { |
| 78 | Editorcxx . . $ Editor# editor = theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> listcxx . . $ structPraatObjects#list. [IOBJECT]. editorscxx . . $ structPraat_Object#editors. [ieditor]; |
| 79 | if (editor) { |
| 80 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (editor -> name); |
| 81 | const char32cxx . . $ char32# *space = str32chrcxx . . $ str32chr(328a9ede0fba853a). (editor -> namecxx . . $ structThing#name..getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), U' '); // editors tend to be called like "3. Sound kanweg" |
| 82 | if (space) { // but not all |
| 83 | conststring32cxx . . $ conststring32# name = space + 1; |
| 84 | if (str32equcxx . . $ `melder/melder_str32.h:122:9`! (name, string)) |
| 85 | return editor; |
| 86 | } |
| 87 | } |
| 88 | } |
| 89 | } |
| 90 | } else { |
| 91 | WHERE_DOWNcxx . . $ `sys/praat.h:199:9`! (1) { |
| 92 | for (int ieditor = 0; ieditor < praat_MAXNUM_EDITORScxx . . $ `sys/praat.h:121:9`!; ieditor ++) { |
| 93 | Editorcxx . . $ Editor# editor = theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> listcxx . . $ structPraatObjects#list. [IOBJECT]. editorscxx . . $ structPraat_Object#editors. [ieditor]; |
| 94 | if (editor && str32equcxx . . $ `melder/melder_str32.h:122:9`! (editor -> namecxx . . $ structThing#name..getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), string)) |
| 95 | return editor; |
| 96 | } |
| 97 | } |
| 98 | } |
| 99 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Editor \"", string, U"\" does not exist."); |
| 100 | } |
| 101 | |
| 102 | Editorcxx . . $ Editor# praat_findEditorByIdcxx . . $ praat_findEditorById(bbc190b40656db0d). (integercxx . . $ integer# id) { |
| 103 | integercxx . . $ integer# IOBJECT; |
| 104 | WHEREcxx . . $ `sys/praat.h:198:9`! (1) { |
| 105 | if (IDcxx . . $ `sys/praat.h:206:9`! == id) { |
| 106 | for (int ieditor = 0; ieditor < praat_MAXNUM_EDITORScxx . . $ `sys/praat.h:121:9`!; ieditor ++) { |
| 107 | Editorcxx . . $ Editor# editor = theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> listcxx . . $ structPraatObjects#list. [IOBJECT]. editorscxx . . $ structPraat_Object#editors. [ieditor]; |
| 108 | if (editor) |
| 109 | return editor; |
| 110 | } |
| 111 | } |
| 112 | } |
| 113 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Editor ", id, U" does not exist."); |
| 114 | } |
| 115 | |
| 116 | static int parseCommaSeparatedArgumentscxx . . $ parseCommaSeparatedArguments(f8a3e31966ed213e). (Interpretercxx . . $ Interpreter# interpreter, char32cxx . . $ char32# *arguments, structStackelcxx . . $ structStackel# *args) { |
| 117 | int narg = 0, depth = 0; |
| 118 | for (char32cxx . . $ char32# *p = arguments; ; p ++) { |
| 119 | const bool endOfArguments = ( *p == U'\0' ); |
| 120 | if (endOfArguments || (*p == U',' && depth == 0)) { |
| 121 | if (narg == MAXIMUM_NUMBER_OF_FIELDScxx . . $ `sys/Ui.h:177:9`!) |
| 122 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Cannot have more than ", MAXIMUM_NUMBER_OF_FIELDScxx . . $ `sys/Ui.h:177:9`!, U" arguments"); |
| 123 | *p = U'\0'; |
| 124 | Formula_Resultcxx . . $ Formula_Result# resultcxx . . $ Formula_Result#Formula_Result(49f6e7a06ebc5aa8).; |
| 125 | Interpreter_anyExpressioncxx . . $ Interpreter_anyExpression(26b9613ed4865362). (interpreter, arguments, & result); |
| 126 | narg ++; |
| 127 | /* |
| 128 | First remove the old contents. |
| 129 | */ |
| 130 | args [narg]. resetcxx . . $ structStackel#reset(49f6e7a06ebc5aa8).(); |
| 131 | #if STACKEL_VARIANTS_ARE_PACKED_IN_A_UNIONcxx . . $ `sys/Formula.h:64:10`! |
| 132 | memset (& args [narg], 0, sizeof (structStackelcxx . . $ structStackel#)); |
| 133 | #endif |
| 134 | /* |
| 135 | Then copy in the new contents. |
| 136 | */ |
| 137 | switch (result. expressionTypecxx . . $ Formula_Result#expressionType.) { |
| 138 | case kFormula_EXPRESSION_TYPE_NUMERICcxx . . $ `sys/Formula.h:24:9`!: { |
| 139 | args [narg]. whichcxx . . $ structStackel#which. = Stackel_NUMBERcxx . . $ `sys/Formula.h:46:10`!; |
| 140 | args [narg]. numbercxx . . $ structStackel#$anonymous_type_0#number. = result. numericResultcxx . . $ Formula_Result#numericResult.; |
| 141 | } break; case kFormula_EXPRESSION_TYPE_STRINGcxx . . $ `sys/Formula.h:25:9`!: { |
| 142 | args [narg]. setStringcxx . . $ structStackel#setString(c3bcb1467d3e4c86). (resultcxx . . $ _autostring#_autostring(39021ecceedcc7d2).. stringResultcxx . . $ Formula_Result#stringResult..movecxx . . $ _autostring#move(bd43c759570f178f).()); |
| 143 | } break; case kFormula_EXPRESSION_TYPE_NUMERIC_VECTORcxx . . $ `sys/Formula.h:26:9`!: { |
| 144 | args [narg]. whichcxx . . $ structStackel#which. = Stackel_NUMERIC_VECTORcxx . . $ `sys/Formula.h:48:10`!; |
| 145 | args [narg]. numericVectorcxx . . $ structStackel#$anonymous_type_0#numericVector. =cxx . . $ vector#`operator=`(958c14910af86093). result. numericVectorResultcxx . . $ Formula_Result#numericVectorResult.; |
| 146 | args [narg]. ownedcxx . . $ structStackel#owned. = result. ownedcxx . . $ Formula_Result#owned.; |
| 147 | result. ownedcxx . . $ Formula_Result#owned. = false; |
| 148 | } break; case kFormula_EXPRESSION_TYPE_NUMERIC_MATRIXcxx . . $ `sys/Formula.h:27:9`!: { |
| 149 | args [narg]. whichcxx . . $ structStackel#which. = Stackel_NUMERIC_MATRIXcxx . . $ `sys/Formula.h:49:10`!; |
| 150 | args [narg]. numericMatrixcxx . . $ structStackel#$anonymous_type_0#numericMatrix. =cxx . . $ matrix#`operator=`(5dfd60dc70a2bbd2). result. numericMatrixResultcxx . . $ Formula_Result#numericMatrixResult.; |
| 151 | args [narg]. ownedcxx . . $ structStackel#owned. = result. ownedcxx . . $ Formula_Result#owned.; |
| 152 | result. ownedcxx . . $ Formula_Result#owned. = false; |
| 153 | } break; case kFormula_EXPRESSION_TYPE_STRING_ARRAYcxx . . $ `sys/Formula.h:30:9`!: { |
| 154 | args [narg]. whichcxx . . $ structStackel#which. = Stackel_STRING_ARRAYcxx . . $ `sys/Formula.h:52:10`!; |
| 155 | args [narg]. stringArraycxx . . $ structStackel#$anonymous_type_0#stringArray. =cxx . . $ _stringvector#`operator=`(15d94a005602ee33). result. stringArrayResultcxx . . $ Formula_Result#stringArrayResult.; |
| 156 | args [narg]. ownedcxx . . $ structStackel#owned. = result. ownedcxx . . $ Formula_Result#owned.; |
| 157 | result. ownedcxx . . $ Formula_Result#owned. = false; |
| 158 | } break; |
| 159 | } |
| 160 | arguments = p + 1; |
| 161 | } else if (*p == U'(' || *p == U'[' || *p == U'{') { |
| 162 | depth ++; |
| 163 | } else if (*p == U')' || *p == U']' || *p == U'}') { |
| 164 | depth --; |
| 165 | } else if (*p == U'\"') { |
| 166 | for (;;) { |
| 167 | p ++; |
| 168 | if (*p == U'\"') { |
| 169 | if (p [1] == U'\"') |
| 170 | p ++; |
| 171 | else |
| 172 | break; |
| 173 | } |
| 174 | } |
| 175 | } |
| 176 | if (endOfArguments) |
| 177 | break; |
| 178 | } |
| 179 | return narg; |
| 180 | } |
| 181 | |
| 182 | bool praat_executeCommandcxx . . $ praat_executeCommand(fa53797037260a84). (Interpretercxx . . $ Interpreter# interpreter, char32cxx . . $ char32# *command) { |
| 183 | if (interpreter) |
| 184 | interpreter -> returnTypecxx . . $ structInterpreter#returnType. = kInterpreter_ReturnTypecxx . . $ kInterpreter_ReturnType#::VOID_cxx . . $ kInterpreter_ReturnType#VOID_.; // clear return type to its default |
| 185 | |
| 186 | static struct structStackelcxx . . $ structStackel# argscxx . . $ structStackel#structStackel(49f6e7a06ebc5aa8). [1 + MAXIMUM_NUMBER_OF_FIELDScxx . . $ `sys/Ui.h:177:9`!]; |
| 187 | //trace (U"praat_executeCommand: ", Melder_pointer (interpreter), U": ", command); |
| 188 | if (command [0] == U'\0' || command [0] == U'#' || command [0] == U'!' || command [0] == U';') |
| 189 | /* Skip empty lines and comments. */; |
| 190 | else if ((command [0] == U'.' || command [0] == U'+' || command [0] == U'-') && Melder_isAsciiUpperCaseLettercxx . . $ Melder_isAsciiUpperCaseLetter(b8d0204ce8416907). (command [1])) { // selection? |
| 191 | integercxx . . $ integer# IOBJECT = praat_findObjectFromStringcxx . . $ praat_findObjectFromString(df2c8148a0293fef). (interpreter, command + 1); |
| 192 | if (command [0] == '.') |
| 193 | praat_deselectAllcxx . . $ praat_deselectAll(49f6e7a06ebc5aa8). (); |
| 194 | if (command [0] == '-') |
| 195 | praat_deselectcxx . . $ praat_deselect(1624ee8275b10bda). (IOBJECT); |
| 196 | else |
| 197 | praat_selectcxx . . $ praat_select(1624ee8275b10bda). (IOBJECT); |
| 198 | praat_showcxx . . $ praat_show(49f6e7a06ebc5aa8). (); |
| 199 | } else if (Melder_isLettercxx . . $ Melder_isLetter(b8d0204ce8416907). (command [0]) && ! Melder_isUpperCaseLettercxx . . $ Melder_isUpperCaseLetter(b8d0204ce8416907). (command [0])) { // all directives start with an ASCII lower-case letter |
| 200 | if (str32nequcxx . . $ `melder/melder_str32.h:123:9`! (command, U"select ", 7)) { |
| 201 | if (str32nequcxx . . $ `melder/melder_str32.h:123:9`! (command + 7, U"all", 3) && (command [10] == U'\0' || command [10] == U' ' || command [10] == U'\t')) { |
| 202 | praat_selectAllcxx . . $ praat_selectAll(49f6e7a06ebc5aa8). (); |
| 203 | praat_showcxx . . $ praat_show(49f6e7a06ebc5aa8). (); |
| 204 | } else { |
| 205 | integercxx . . $ integer# IOBJECT = praat_findObjectFromStringcxx . . $ praat_findObjectFromString(df2c8148a0293fef). (interpreter, command + 7); |
| 206 | praat_deselectAllcxx . . $ praat_deselectAll(49f6e7a06ebc5aa8). (); |
| 207 | praat_selectcxx . . $ praat_select(1624ee8275b10bda). (IOBJECT); |
| 208 | praat_showcxx . . $ praat_show(49f6e7a06ebc5aa8). (); |
| 209 | } |
| 210 | } else if (str32nequcxx . . $ `melder/melder_str32.h:123:9`! (command, U"plus ", 5)) { |
| 211 | integercxx . . $ integer# IOBJECT = praat_findObjectFromStringcxx . . $ praat_findObjectFromString(df2c8148a0293fef). (interpreter, command + 5); |
| 212 | praat_selectcxx . . $ praat_select(1624ee8275b10bda). (IOBJECT); |
| 213 | praat_showcxx . . $ praat_show(49f6e7a06ebc5aa8). (); |
| 214 | } else if (str32nequcxx . . $ `melder/melder_str32.h:123:9`! (command, U"minus ", 6)) { |
| 215 | integercxx . . $ integer# IOBJECT = praat_findObjectFromStringcxx . . $ praat_findObjectFromString(df2c8148a0293fef). (interpreter, command + 6); |
| 216 | praat_deselectcxx . . $ praat_deselect(1624ee8275b10bda). (IOBJECT); |
| 217 | praat_showcxx . . $ praat_show(49f6e7a06ebc5aa8). (); |
| 218 | } else if (str32nequcxx . . $ `melder/melder_str32.h:123:9`! (command, U"echo ", 5)) { |
| 219 | MelderInfo_opencxx . . $ MelderInfo_open(49f6e7a06ebc5aa8). (); |
| 220 | MelderInfo_writecxx . . $ MelderInfo_write(3eb398314feba58b). (command + 5); |
| 221 | MelderInfo_closecxx . . $ MelderInfo_close(49f6e7a06ebc5aa8). (); |
| 222 | } else if (str32nequcxx . . $ `melder/melder_str32.h:123:9`! (command, U"clearinfo", 9)) { |
| 223 | Melder_clearInfocxx . . $ Melder_clearInfo(49f6e7a06ebc5aa8). (); |
| 224 | } else if (str32nequcxx . . $ `melder/melder_str32.h:123:9`! (command, U"print ", 6)) { |
| 225 | MelderInfo_writecxx . . $ MelderInfo_write(3eb398314feba58b). (command + 6); |
| 226 | MelderInfo_draincxx . . $ MelderInfo_drain(49f6e7a06ebc5aa8). (); |
| 227 | } else if (str32nequcxx . . $ `melder/melder_str32.h:123:9`! (command, U"printtab", 8)) { |
| 228 | MelderInfo_writecxx . . $ MelderInfo_write(3eb398314feba58b). (U"\t"); |
| 229 | MelderInfo_draincxx . . $ MelderInfo_drain(49f6e7a06ebc5aa8). (); |
| 230 | } else if (str32nequcxx . . $ `melder/melder_str32.h:123:9`! (command, U"printline", 9)) { |
| 231 | if (command [9] == ' ') MelderInfo_writecxx . . $ MelderInfo_write(3eb398314feba58b). (command + 10); |
| 232 | MelderInfo_writecxx . . $ MelderInfo_write(3eb398314feba58b). (U"\n"); |
| 233 | MelderInfo_draincxx . . $ MelderInfo_drain(49f6e7a06ebc5aa8). (); |
| 234 | } else if (str32nequcxx . . $ `melder/melder_str32.h:123:9`! (command, U"fappendinfo ", 12)) { |
| 235 | if (theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. != & theForegroundPraatObjectscxx . . $ theForegroundPraatObjects.) |
| 236 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"The script command “fappendinfo” is not available inside pictures."); |
| 237 | structMelderFilecxx . . $ structMelderFile# file { }; |
| 238 | Melder_relativePathToFilecxx . . $ Melder_relativePathToFile(82691f2ee21fbb13). (command + 12, & file); |
| 239 | MelderFile_appendText_ecxx . . $ MelderFile_appendText_e(8fa576db0692df65). (& file, Melder_getInfocxx . . $ Melder_getInfo(1912f6684645c851). ()); |
| 240 | } else if (str32nequcxx . . $ `melder/melder_str32.h:123:9`! (command, U"unix ", 5)) { |
| 241 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (praat_commandsWithExternalSideEffectsAreAllowed (), |
| 242 | U"The script command “unix” is not available inside manuals."); |
| 243 | try { |
| 244 | Melder_runSystemcxx . . $ Melder_runSystem(ff00d524ab0355ec). (command + 5); |
| 245 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 246 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Unix command “", command + 5, U"” returned error status;\n" |
| 247 | U"if you want to ignore this, use `unix_nocheck' instead of `unix'."); |
| 248 | } |
| 249 | } else if (str32nequcxx . . $ `melder/melder_str32.h:123:9`! (command, U"unix_nocheck ", 13)) { |
| 250 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (praat_commandsWithExternalSideEffectsAreAllowed (), |
| 251 | U"The script command “unix_nocheck” is not available inside manuals."); |
| 252 | try { |
| 253 | Melder_runSystemcxx . . $ Melder_runSystem(ff00d524ab0355ec). (command + 13); |
| 254 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 255 | Melder_clearErrorcxx . . $ Melder_clearError(49f6e7a06ebc5aa8). (); |
| 256 | } |
| 257 | } else if (str32nequcxx . . $ `melder/melder_str32.h:123:9`! (command, U"system ", 7)) { |
| 258 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (praat_commandsWithExternalSideEffectsAreAllowed (), |
| 259 | U"The script command “system” is not available inside manuals."); |
| 260 | try { |
| 261 | Melder_runSystemcxx . . $ Melder_runSystem(ff00d524ab0355ec). (command + 7); |
| 262 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 263 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"System command “", command + 7, U"” returned error status;\n" |
| 264 | U"if you want to ignore this, use “system_nocheck” instead of “system”."); |
| 265 | } |
| 266 | } else if (str32nequcxx . . $ `melder/melder_str32.h:123:9`! (command, U"system_nocheck ", 15)) { |
| 267 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (praat_commandsWithExternalSideEffectsAreAllowed (), |
| 268 | U"The script command “system_nocheck” is not available inside manuals."); |
| 269 | try { |
| 270 | Melder_runSystemcxx . . $ Melder_runSystem(ff00d524ab0355ec). (command + 15); |
| 271 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 272 | Melder_clearErrorcxx . . $ Melder_clearError(49f6e7a06ebc5aa8). (); |
| 273 | } |
| 274 | } else if (str32nequcxx . . $ `melder/melder_str32.h:123:9`! (command, U"nowarn ", 7)) { |
| 275 | autoMelderWarningOffcxx . . $ autoMelderWarningOff# nowarncxx . . $ autoMelderWarningOff#autoMelderWarningOff(49f6e7a06ebc5aa8).; |
| 276 | return praat_executeCommandcxx . . $ praat_executeCommand(fa53797037260a84). (interpreter, command + 7); |
| 277 | } else if (str32nequcxx . . $ `melder/melder_str32.h:123:9`! (command, U"noprogress ", 11)) { |
| 278 | autoMelderProgressOffcxx . . $ autoMelderProgressOff# noprogresscxx . . $ autoMelderProgressOff#autoMelderProgressOff(49f6e7a06ebc5aa8).; |
| 279 | return praat_executeCommandcxx . . $ praat_executeCommand(fa53797037260a84). (interpreter, command + 11); |
| 280 | } else if (str32nequcxx . . $ `melder/melder_str32.h:123:9`! (command, U"nocheck ", 8)) { |
| 281 | try { |
| 282 | return praat_executeCommandcxx . . $ praat_executeCommand(fa53797037260a84). (interpreter, command + 8); |
| 283 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 284 | Melder_clearErrorcxx . . $ Melder_clearError(49f6e7a06ebc5aa8). (); |
| 285 | return false; |
| 286 | } |
| 287 | } else if (str32nequcxx . . $ `melder/melder_str32.h:123:9`! (command, U"demo ", 5)) { |
| 288 | autoDemoOpencxx . . $ autoDemoOpen# democxx . . $ autoDemoOpen#autoDemoOpen(49f6e7a06ebc5aa8).; |
| 289 | return praat_executeCommandcxx . . $ praat_executeCommand(fa53797037260a84). (interpreter, command + 5); |
| 290 | } else if (str32nequcxx . . $ `melder/melder_str32.h:123:9`! (command, U"asynchronous ", 13)) { |
| 291 | autoMelderAsynchronouscxx . . $ autoMelderAsynchronous# asynchronouscxx . . $ autoMelderAsynchronous#autoMelderAsynchronous(49f6e7a06ebc5aa8).; |
| 292 | return praat_executeCommandcxx . . $ praat_executeCommand(fa53797037260a84). (interpreter, command + 13); |
| 293 | } else if (str32nequcxx . . $ `melder/melder_str32.h:123:9`! (command, U"pause ", 6) || str32equcxx . . $ `melder/melder_str32.h:122:9`! (command, U"pause")) { |
| 294 | if (theCurrentPraatApplicationcxx . . $ theCurrentPraatApplication. -> batchcxx . . $ structPraatApplication#batch.) |
| 295 | return true; // in batch we ignore pause statements |
| 296 | const Editorcxx . . $ Editor# optionalPauseWindowOwningEditor = interpreter -> optionalDynamicEnvironmentEditorcxx . . $ structInterpreter#optionalDynamicEnvironmentEditor(480fba2ddcd094f3).(); |
| 297 | const GuiWindowcxx . . $ GuiWindow# parentShell = ( optionalPauseWindowOwningEditor ? optionalPauseWindowOwningEditor -> windowFormcxx . . $ structEditor#windowForm. : theCurrentPraatApplicationcxx . . $ theCurrentPraatApplication. -> topShellcxx . . $ structPraatApplication#topShell. ); |
| 298 | UiPause_pauseScriptcxx . . $ UiPause_pauseScript(2569ff2ad22a95d). (parentShell, optionalPauseWindowOwningEditor, interpreter, str32equcxx . . $ `melder/melder_str32.h:122:9`! (command, U"pause") ? U"..." : command + 6); |
| 299 | } else if (str32nequcxx . . $ `melder/melder_str32.h:123:9`! (command, U"execute ", 8)) { |
| 300 | //TRACE |
| 301 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"interpreter: ", Melder_pointer (interpreter)); |
| 302 | if (interpreter) |
| 303 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"stack: ", Melder_pointer (interpreter -> owningInterpreterStack)); |
| 304 | praat_runOldExecuteCommandcxx . . $ praat_runOldExecuteCommand(5a4a4121a05e045). (interpreter ? interpreter -> owningInterpreterStackcxx . . $ structInterpreter#owningInterpreterStack. : nullptr, command + 8); |
| 305 | } else if (str32nequcxx . . $ `melder/melder_str32.h:123:9`! (command, U"editor", 6)) { // deprecated |
| 306 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (praat_commandsWithExternalSideEffectsAreAllowed (), |
| 307 | U"The script command “editor” is not available inside manuals."); |
| 308 | if (command [6] == U' ' && Melder_isLettercxx . . $ Melder_isLetter(b8d0204ce8416907). (command [7])) { |
| 309 | interpreter -> setDynamicEditorEnvironmentFromEditorcxx . . $ structInterpreter#setDynamicEditorEnvironmentFromEditor(804f629ae7a06da5). (praat_findEditorFromStringcxx . . $ praat_findEditorFromString(2ddda295cd13730e). (command + 7)); |
| 310 | } else if (command [6] == U'\0') { |
| 311 | if (interpreter && interpreter -> wasStartedFromEditorEnvironmentcxx . . $ structInterpreter#wasStartedFromEditorEnvironment(77ce49a7840d23c7).()) |
| 312 | /* |
| 313 | The script directive |
| 314 | editor |
| 315 | (without arguments) should set the interpreter's environment back to the editor that started the script. |
| 316 | */ |
| 317 | interpreter -> setDynamicFromOwningEditorEnvironmentcxx . . $ structInterpreter#setDynamicFromOwningEditorEnvironment(ced63f7c635d850d).(); // TODO: what if the owener has been orphaned? |
| 318 | else |
| 319 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"The script command “editor” requires an argument when called from outside an editor."); |
| 320 | } else { |
| 321 | Interpreter_voidExpressioncxx . . $ Interpreter_voidExpression(c79bee1e2231f904). (interpreter, command); |
| 322 | } |
| 323 | } else if (str32nequcxx . . $ `melder/melder_str32.h:123:9`! (command, U"endeditor", 9)) { |
| 324 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (praat_commandsWithExternalSideEffectsAreAllowed (), |
| 325 | U"The script command “endeditor” is not available inside manuals."); |
| 326 | interpreter -> nullifyDynamicEditorEnvironmentcxx . . $ structInterpreter#nullifyDynamicEditorEnvironment(ced63f7c635d850d).(); |
| 327 | } else if (str32nequcxx . . $ `melder/melder_str32.h:123:9`! (command, U"filedelete ", 11)) { |
| 328 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (praat_commandsWithExternalSideEffectsAreAllowed (), |
| 329 | U"The script command “filedelete” is not available inside manuals."); |
| 330 | const char32cxx . . $ char32# *p = command + 11; |
| 331 | structMelderFilecxx . . $ structMelderFile# file { }; |
| 332 | while (*p == U' ' || *p == U'\t') p ++; |
| 333 | if (*p == U'\0') |
| 334 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Missing file name after “filedelete”."); |
| 335 | Melder_relativePathToFilecxx . . $ Melder_relativePathToFile(82691f2ee21fbb13). (p, & file); |
| 336 | MelderFile_deletecxx . . $ MelderFile_delete(1145552d769d7b5d). (& file); |
| 337 | } else if (str32nequcxx . . $ `melder/melder_str32.h:123:9`! (command, U"fileappend ", 11)) { |
| 338 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (praat_commandsWithExternalSideEffectsAreAllowed (), |
| 339 | U"The script command “fileappend” is not available inside manuals."); |
| 340 | const char32cxx . . $ char32# *p = command + 11; |
| 341 | char32cxx . . $ char32# path [kMelder_MAXPATHcxx . . $ `melder/melder_files.h:30:9`!+1], *q = & path [0]; |
| 342 | while (*p == U' ' || *p == U'\t') p ++; |
| 343 | if (*p == U'\0') |
| 344 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Missing file name after “fileappend”."); |
| 345 | if (*p == '\"') { |
| 346 | for (;;) { |
| 347 | char32cxx . . $ char32# kar = * ++ p; |
| 348 | if (kar == U'\"') if (* ++ p == U'\"') *q ++ = U'\"'; else break; |
| 349 | else if (kar == U'\0') break; |
| 350 | else *q ++ = kar; |
| 351 | } |
| 352 | } else { |
| 353 | for (;;) { |
| 354 | char32cxx . . $ char32# kar = * p; |
| 355 | if (kar == U'\0' || kar == U' ' || kar == U'\t') break; |
| 356 | *q ++ = kar; |
| 357 | p ++; |
| 358 | } |
| 359 | } |
| 360 | *q = U'\0'; |
| 361 | if (*p == U' ' || *p == U'\t') { |
| 362 | structMelderFilecxx . . $ structMelderFile# file { }; |
| 363 | Melder_relativePathToFilecxx . . $ Melder_relativePathToFile(82691f2ee21fbb13). (path, & file); |
| 364 | MelderFile_appendText_ecxx . . $ MelderFile_appendText_e(8fa576db0692df65). (& file, p + 1); |
| 365 | } |
| 366 | } else { |
| 367 | /* |
| 368 | This must be a formula command: |
| 369 | proc (args) |
| 370 | */ |
| 371 | Interpreter_voidExpressioncxx . . $ Interpreter_voidExpression(c79bee1e2231f904). (interpreter, command); |
| 372 | } |
| 373 | } else { /* Simulate menu choice. */ |
| 374 | bool hasDots = false, hasColon = false; |
| 375 | |
| 376 | /* Parse command line into command and arguments. */ |
| 377 | /* The separation is formed by the three dots or a colon. */ |
| 378 | |
| 379 | char32cxx . . $ char32# *arguments = & command [0]; |
| 380 | for (arguments = & command [0]; *arguments != U'\0'; arguments ++) { |
| 381 | if (*arguments == U':') { |
| 382 | hasColon = true; |
| 383 | if (arguments [1] == U'\0') { |
| 384 | arguments = & arguments [1]; // empty string |
| 385 | } else { |
| 386 | if (arguments [1] != U' ') |
| 387 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"There should be a space after the colon."); |
| 388 | arguments [1] = U'\0'; // new end of "command" |
| 389 | arguments += 2; // the arguments start after the space |
| 390 | } |
| 391 | break; |
| 392 | } |
| 393 | if (*arguments == U'.' && arguments [1] == U'.' && arguments [2] == U'.') { |
| 394 | hasDots = true; |
| 395 | arguments += 3; |
| 396 | if (*arguments == U'\0') { |
| 397 | // empty string |
| 398 | } else { |
| 399 | if (*arguments != U' ') |
| 400 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"There should be a space after the three dots."); |
| 401 | *arguments = U'\0'; // new end of "command" |
| 402 | arguments ++; // the arguments start after the space |
| 403 | } |
| 404 | break; |
| 405 | } |
| 406 | } |
| 407 | |
| 408 | /* See if command exists and is available; ignore separators. */ |
| 409 | /* First try loose commands, then fixed commands. */ |
| 410 | |
| 411 | integercxx . . $ integer# narg; |
| 412 | char32cxx . . $ char32# command2 [200]; |
| 413 | if (hasColon) { |
| 414 | narg = parseCommaSeparatedArgumentscxx . . $ parseCommaSeparatedArguments(f8a3e31966ed213e). (interpreter, arguments, args); |
| 415 | str32cpycxx . . $ str32cpy(6ab934322573b179). (command2, command); |
| 416 | char32cxx . . $ char32# *colon = str32chrcxx . . $ str32chr(328a9ede0fba853a). (command2, U':'); |
| 417 | colon [0] = colon [1] = colon [2] = U'.'; |
| 418 | colon [3] = U'\0'; |
| 419 | } |
| 420 | if (theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. == & theForegroundPraatObjectscxx . . $ theForegroundPraatObjects. && interpreter && interpreter -> hasDynamicEnvironmentEditorcxx . . $ structInterpreter#hasDynamicEnvironmentEditor(77ce49a7840d23c7).()) { |
| 421 | if (hasColon) |
| 422 | Editor_doMenuCommandcxx . . $ Editor_doMenuCommand(11ddb24ea6d4513). (interpreter -> optionalDynamicEnvironmentEditorcxx . . $ structInterpreter#optionalDynamicEnvironmentEditor(480fba2ddcd094f3).(), command2, narg, args, nullptr, interpreter); |
| 423 | else |
| 424 | Editor_doMenuCommandcxx . . $ Editor_doMenuCommand(11ddb24ea6d4513). (interpreter -> optionalDynamicEnvironmentEditorcxx . . $ structInterpreter#optionalDynamicEnvironmentEditor(480fba2ddcd094f3).(), command, 0, nullptr, arguments, interpreter); |
| 425 | } else if (! praat_commandsWithExternalSideEffectsAreAllowedcxx . . $ praat_commandsWithExternalSideEffectsAreAllowed(c9857a73d68e59ba). () && |
| 426 | (str32nequcxx . . $ `melder/melder_str32.h:123:9`! (command, U"Save ", 5) || |
| 427 | str32nequcxx . . $ `melder/melder_str32.h:123:9`! (command, U"Write ", 6) || |
| 428 | str32nequcxx . . $ `melder/melder_str32.h:123:9`! (command, U"Append to ", 10) || |
| 429 | str32nequcxx . . $ `melder/melder_str32.h:123:9`! (command, U"Quit", 4))) |
| 430 | { |
| 431 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Commands that write files (including Quit) are not available inside manuals."); |
| 432 | } else { |
| 433 | bool theCommandIsAnExistingAction = false; |
| 434 | try { |
| 435 | if (hasColon) |
| 436 | theCommandIsAnExistingAction = praat_doActioncxx . . $ praat_doAction(738317ad6fa3f573). (command2, narg, args, interpreter); |
| 437 | else |
| 438 | theCommandIsAnExistingAction = praat_doActioncxx . . $ praat_doAction(3dcbaa6862792959). (command, arguments, interpreter); |
| 439 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 440 | /* |
| 441 | We only get here if the command *was* an existing action. |
| 442 | Anything could have gone wrong in its execution, |
| 443 | but one invisible problem can be checked here. |
| 444 | */ |
| 445 | if (hasDots && arguments [0] != U'\0' && arguments [Melder_lengthcxx . . $ Melder_length(3fae411214b133ad). (arguments) - 1] == U' ') |
| 446 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"It may be helpful to remove the trailing spaces in \"", arguments, U"\"."); |
| 447 | else |
| 448 | throw; |
| 449 | } |
| 450 | if (! theCommandIsAnExistingAction) { |
| 451 | bool theCommandIsAnExistingMenuCommand = false; |
| 452 | try { |
| 453 | if (hasColon) |
| 454 | theCommandIsAnExistingMenuCommand = praat_doMenuCommandcxx . . $ praat_doMenuCommand(738317ad6fa3f573). (command2, narg, args, interpreter); |
| 455 | else |
| 456 | theCommandIsAnExistingMenuCommand = praat_doMenuCommandcxx . . $ praat_doMenuCommand(3dcbaa6862792959). (command, arguments, interpreter); |
| 457 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 458 | /* |
| 459 | We only get here if the command *was* an existing menu command. |
| 460 | Anything could have gone wrong in its execution, |
| 461 | but one invisible problem can be checked here. |
| 462 | */ |
| 463 | if (hasDots && arguments [0] != U'\0' && arguments [Melder_lengthcxx . . $ Melder_length(3fae411214b133ad). (arguments) - 1] == U' ') |
| 464 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"It may be helpful to remove the trailing spaces in “", arguments, U"”."); |
| 465 | else |
| 466 | throw; |
| 467 | } |
| 468 | if (! theCommandIsAnExistingMenuCommand) { |
| 469 | const integercxx . . $ integer# length = Melder_lengthcxx . . $ Melder_length(3fae411214b133ad). (command); |
| 470 | if (str32nequcxx . . $ `melder/melder_str32.h:123:9`! (command, U"ARGS ", 5)) |
| 471 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Command “ARGS” no longer supported. Instead use “form” and “endform”."); |
| 472 | else if (str32chrcxx . . $ str32chr(328a9ede0fba853a). (command, U'=')) |
| 473 | if (command [0] == U'_') |
| 474 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Command “", command, U"” not recognized.\n" |
| 475 | U"Probable cause: you are trying to use a variable name that starts with an underscore."); |
| 476 | else |
| 477 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Command “", command, U"” not recognized.\n" |
| 478 | U"Probable cause: you are trying to use a variable name that starts with a capital letter."); |
| 479 | else if (length >= 1 && Melder_isHorizontalSpacecxx . . $ Melder_isHorizontalSpace(b8d0204ce8416907). (command [length - 1])) |
| 480 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Command “", command, U"” not available for current selection. " |
| 481 | U"It may be helpful to remove the trailing spaces."); |
| 482 | else if (length >= 2 && Melder_isHorizontalSpacecxx . . $ Melder_isHorizontalSpace(b8d0204ce8416907). (command [length - 2]) && command [length - 1] == U':') |
| 483 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Command “", command, U"” not available for current selection. " |
| 484 | U"It may be helpful to remove the space before the colon."); |
| 485 | else if (str32nequcxx . . $ `melder/melder_str32.h:123:9`! (command, U"\"ooTextFile\"", 12)) |
| 486 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Command “", command, U"” not available for current selection. " |
| 487 | U"It is possible that this file is not a Praat script but a Praat data file that you can open with “Read from file...”."); |
| 488 | else { |
| 489 | if (interpreter && interpreter -> wasStartedFromEditorEnvironmentcxx . . $ structInterpreter#wasStartedFromEditorEnvironment(77ce49a7840d23c7).()) |
| 490 | if (interpreter -> hasDynamicEnvironmentEditorcxx . . $ structInterpreter#hasDynamicEnvironmentEditor(77ce49a7840d23c7).()) |
| 491 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Command “", command, U"” not available in ", interpreter -> optionalDynamicEditorEnvironmentClassName(), U"."); |
| 492 | else |
| 493 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Command “", command, U"” not available for current selection.\n" |
| 494 | U"Perhaps this is a ", interpreter -> optionalOwningEditorEnvironmentClassName(), U" command?"); |
| 495 | else |
| 496 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Command “", command, U"” not available for current selection."); |
| 497 | } |
| 498 | } |
| 499 | } |
| 500 | } |
| 501 | praat_updateSelectioncxx . . $ praat_updateSelection(49f6e7a06ebc5aa8). (); |
| 502 | } |
| 503 | return true; |
| 504 | } |
| 505 | |
| 506 | void praat_executeCommandFromStandardInputcxx . . $ praat_executeCommandFromStandardInput(ff00d524ab0355ec). (conststring32cxx . . $ conststring32# programName) { |
| 507 | char command8 [1000]; // can be recursive |
| 508 | /* |
| 509 | FIXME: implement for Windows. |
| 510 | */ |
| 511 | for (;;) { |
| 512 | printf ("%s > ", Melder_peek32to8 (programName)); |
| 513 | if (! fgets (command8, 999, stdincxx . . $ `<external>/232824719582829767/stdio.h:153:9`!)) |
| 514 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Cannot read input."); |
| 515 | char *newLine = strchr (command8, '\n'); |
| 516 | if (newLine) |
| 517 | *newLine = '\0'; |
| 518 | autostring32cxx . . $ autostring32# command32 = Melder_8to32_ecxx . . $ Melder_8to32_e(f01fe69d6ed2498b). (command8); |
| 519 | try { |
| 520 | (void) praat_executeCommandcxx . . $ praat_executeCommand(fa53797037260a84). (nullptr, command32.getcxx . . $ _autostring#get(5a2a78a048fb49a8).()); |
| 521 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 522 | Melder_flushErrorcxx . . $ Melder_flushError(6298c93241566110). (programName, U": Command “", Melder_peek8to32_u (command8), U"” not executed."); |
| 523 | } |
| 524 | } |
| 525 | } |
| 526 | |
| 527 | void praat_executeScript_noGUIcxx . . $ praat_executeScript_noGUI(36849bf2e291e39f). (MelderFilecxx . . $ MelderFile# file, bool fullTrust) { |
| 528 | /* |
| 529 | The problem here occurs when plug-in initialization (typically, `setup.praat`) posts a pause window, |
| 530 | as happens e.g. in the VocalToolkit plug-in if the Praat version is too old. |
| 531 | This function will return while the pause window is on the screen, and |
| 532 | Praat will happily initialize the next plug-in. |
| 533 | Quick fix: allow up to 10 InterpreterStacks. |
| 534 | Long-term solution TODO: make pause windows in plug-in initializers modal. |
| 535 | */ |
| 536 | constexpr integercxx . . $ integer# NUMBER_OF_STACKS = 10; |
| 537 | static autoInterpreterStackcxx . . $ autoInterpreterStack# interpreterStackscxx . . $ autoSomeThing#autoSomeThing(49f6e7a06ebc5aa8). [NUMBER_OF_STACKS]; |
| 538 | static integercxx . . $ integer# stackNumber = 0; |
| 539 | stackNumber = (stackNumber + 1) % NUMBER_OF_STACKS; |
| 540 | autoInterpreterStackcxx . . $ autoInterpreterStack#& interpreterStack = interpreterStacks [stackNumber]; |
| 541 | try { |
| 542 | interpreterStack =cxx . . $ autoSomeThing#`operator=`(80cc59814f7161e8). InterpreterStack_createcxx . . $ InterpreterStack_create(91aa183261e4fa82). (Editorcxx . . $ Editor# (nullptr)); |
| 543 | autostring32cxx . . $ autostring32# text = MelderFile_readTextcxx . . $ MelderFile_readText(2312d39ae70aea26). (file); |
| 544 | {// scope |
| 545 | autoMelderFileSetCurrentFoldercxx . . $ autoMelderFileSetCurrentFolder# foldercxx . . $ autoMelderFileSetCurrentFolder#autoMelderFileSetCurrentFolder(1145552d769d7b5d). (file); // so that script-relative file names can be used for including include files |
| 546 | Melder_includeIncludeFilescxx . . $ Melder_includeIncludeFiles(2d5e149ff849c92b). (& text); |
| 547 | } // back to the default directory of the caller |
| 548 | autoInterpretercxx . . $ autoInterpreter# interpreter = Interpreter_createFromEnvironmentcxx . . $ Interpreter_createFromEnvironment(2a446a9b6f15a803). ( |
| 549 | interpreterStack.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), // owner always needed |
| 550 | Editorcxx . . $ Editor# (nullptr), // never used inside an Editor window |
| 551 | file // so that script-relative file names can be used inside the script |
| 552 | ); |
| 553 | interpreterStack ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). emptyAllcxx . . $ structInterpreterStack#emptyAll(49f6e7a06ebc5aa8). (); |
| 554 | Interpreter_rememberScript_overridecxx . . $ Interpreter_rememberScript_override(a0c4c87353b136f2). (interpreter.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), file, fullTrust && str32strcxx . . $ str32str(2de17cd8f7c584a6). (text.getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), U"\n# --FULL-TRUST\n")); |
| 555 | interpreterStack ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). runDowncxx . . $ structInterpreterStack#runDown(f108da249e59f621). (interpretercxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f)..movecxx . . $ autoSomeThing#move(25acc3554b7d1642).(), textcxx . . $ _autostring#_autostring(39021ecceedcc7d2)..movecxx . . $ _autostring#move(bd43c759570f178f).(), false); |
| 556 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 557 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Script ", file, U" not completed."); |
| 558 | } |
| 559 | } |
| 560 | |
| 561 | void praat_runScriptcxx . . $ praat_runScript(3d0e5aa21c8672cd). (InterpreterStackcxx . . $ InterpreterStack# interpreterStack, conststring32cxx . . $ conststring32# fileName, integercxx . . $ integer# narg, Stackelcxx . . $ Stackel# args, Editorcxx . . $ Editor# optionalInterpreterOwningEditor) { |
| 562 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (interpreterStack); |
| 563 | //Melder_assert (Melder_backgrounding); |
| 564 | |
| 565 | Interpretercxx . . $ Interpreter# parentInterpreter = interpreterStack -> current_acxx . . $ structInterpreterStack#current_a(f106979d91fbaa9d). (); |
| 566 | if (parentInterpreter -> isInSecondPasscxx . . $ structInterpreter#isInSecondPass.) { |
| 567 | interpreterStack -> resumeNextLevelInSecondPasscxx . . $ structInterpreterStack#resumeNextLevelInSecondPass(49f6e7a06ebc5aa8). (); |
| 568 | } else { |
| 569 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (MelderFolder_equal (Melder_peekWorkingDirectory (), & parentInterpreter -> workingDirectory)); |
| 570 | //autoMelderSetCurrentFolder folder (& parentInterpreter -> workingDirectory); // TODO: is this superfluous, i.e. does the previous assertion never fire? |
| 571 | |
| 572 | structMelderFilecxx . . $ structMelderFile# file { }; |
| 573 | try { |
| 574 | Melder_relativePathToFilecxx . . $ Melder_relativePathToFile(82691f2ee21fbb13). (fileName, & file); |
| 575 | autostring32cxx . . $ autostring32# text = MelderFile_readTextcxx . . $ MelderFile_readText(2312d39ae70aea26). (& file); |
| 576 | /* |
| 577 | We switch between default directories no fewer than four times: |
| 578 | 1. runScript() tends to be called from a script that we call the "caller"; |
| 579 | when we enter runScript(), the default directory is the caller's folder, |
| 580 | as was appropriate for the use of file names in the caller before runScript(), |
| 581 | which had to be interpreted relative to the caller's folder. |
| 582 | 2. runScript() will call a script that we call the "callee"; |
| 583 | include files have to be included from the callee's folder. |
| 584 | 3. For expanding any infile/outfile/folder arguments to runScript(), |
| 585 | we have to be back in the caller's folder. |
| 586 | 4. Inside the callee, file names will have to be interpreted relative to the callee's folder. |
| 587 | 5. After runScript() finishes, we will have to be back in the caller's folder, |
| 588 | so that the use of file names in the caller after runScript() |
| 589 | will be interpreted relative to the caller's folder again. |
| 590 | */ |
| 591 | {// scope |
| 592 | autoMelderFileSetCurrentFoldercxx . . $ autoMelderFileSetCurrentFolder# foldercxx . . $ autoMelderFileSetCurrentFolder#autoMelderFileSetCurrentFolder(1145552d769d7b5d). (& file); // so that callee-relative file names can be used for including include files |
| 593 | Melder_includeIncludeFilescxx . . $ Melder_includeIncludeFiles(2d5e149ff849c92b). (& text); |
| 594 | } // back to the default directory of the caller |
| 595 | autoInterpretercxx . . $ autoInterpreter# me = Interpreter_createFromEnvironmentcxx . . $ Interpreter_createFromEnvironment(2a446a9b6f15a803). ( |
| 596 | interpreterStack, // owner always needed |
| 597 | optionalInterpreterOwningEditor, |
| 598 | & file // so that callee-relative file names can be used inside the script |
| 599 | ); |
| 600 | Interpreter_readParameterscxx . . $ Interpreter_readParameters(9dd4ed1655057857). (me.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), text.getcxx . . $ _autostring#get(5a2a78a048fb49a8).()); // TODO: should become a field of structInterpreter |
| 601 | mycxx . . $ `melder/melder.h:44:9`! textcxx . . $ structInterpreter#text. =cxx . . $ _autostring#`operator=`(f562943cbc4bcf37). text.movecxx . . $ _autostring#move(bd43c759570f178f).(); |
| 602 | Interpreter_getArgumentsFromArgscxx . . $ Interpreter_getArgumentsFromArgs(2d2c4569794feab0). (me.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), narg, args); // interpret caller-relative paths for infile/outfile/folder arguments |
| 603 | Interpreter_rememberScriptcxx . . $ Interpreter_rememberScript(a0c4c87353b136f2). (me.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), & file, ! parentInterpreter -> scriptReferencecxx . . $ structInterpreter#scriptReference. || parentInterpreter -> scriptReferencecxx . . $ structInterpreter#scriptReference. -> trustedcxx . . $ structScript#trusted.); |
| 604 | interpreterStack -> runDowncxx . . $ structInterpreterStack#runDown(f108da249e59f621). (mecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f)..movecxx . . $ autoSomeThing#move(25acc3554b7d1642).(), autostring32cxx . . $ _autostring#_autostring(49f6e7a06ebc5aa8).(), false); // back to the default directory of the caller |
| 605 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 606 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Script ", & file, U" not completed."); // don't refer to 'fileName', because its contents may have changed |
| 607 | } |
| 608 | } |
| 609 | } |
| 610 | |
| 611 | void praat_runNotebookcxx . . $ praat_runNotebook(3d0e5aa21c8672cd). (InterpreterStackcxx . . $ InterpreterStack# interpreterStack, conststring32cxx . . $ conststring32# fileName, integercxx . . $ integer# narg, Stackelcxx . . $ Stackel# args, Editorcxx . . $ Editor# optionalInterpreterOwningEditor) { |
| 612 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (interpreterStack); |
| 613 | //Melder_assert (Melder_backgrounding); |
| 614 | |
| 615 | //TRACE |
| 616 | Interpretercxx . . $ Interpreter# parentInterpreter = interpreterStack -> current_acxx . . $ structInterpreterStack#current_a(f106979d91fbaa9d). (); |
| 617 | if (parentInterpreter -> isInSecondPasscxx . . $ structInterpreter#isInSecondPass.) { |
| 618 | interpreterStack -> resumeNextLevelInSecondPasscxx . . $ structInterpreterStack#resumeNextLevelInSecondPass(49f6e7a06ebc5aa8). (); |
| 619 | } else { |
| 620 | structMelderFoldercxx . . $ structMelderFolder# workingDirectory; |
| 621 | Melder_getCurrentFoldercxx . . $ Melder_getCurrentFolder(63f38d3b6b86d1dc). (& workingDirectory); |
| 622 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (MelderFolder_equal (& workingDirectory, & parentInterpreter -> workingDirectory)); |
| 623 | |
| 624 | structMelderFilecxx . . $ structMelderFile# file { }; |
| 625 | try { |
| 626 | Melder_relativePathToFilecxx . . $ Melder_relativePathToFile(82691f2ee21fbb13). (fileName, & file); |
| 627 | autostring32cxx . . $ autostring32# text = MelderFile_readTextcxx . . $ MelderFile_readText(2312d39ae70aea26). (& file); |
| 628 | if (! Melder_startsWithcxx . . $ Melder_startsWith(1652f10ed0f82783). (text.getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), U"\"")) |
| 629 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"File ", & file, U" is not a Praat notebook."); |
| 630 | /* |
| 631 | We switch between default directories no fewer than four times: |
| 632 | 1. runScript() tends to be called from a script that we call the "caller"; |
| 633 | when we enter runScript(), the working directory is the caller's folder |
| 634 | (set upon Interpreter creation as the folder where the calling script is, |
| 635 | though perhaps changed later in that script by `setWorkingDirectory`), |
| 636 | as was appropriate for the use of file names in the caller before runScript(), |
| 637 | which had to be interpreted relative to the caller's folder. |
| 638 | 2. runScript() will call a script that we call the "callee"; |
| 639 | include files have to be included from the callee's folder. |
| 640 | 3. For expanding any infile/outfile/folder arguments to runScript(), |
| 641 | we have to be back in the caller's folder. |
| 642 | 4. Inside the callee, file names will have to be interpreted relative to the callee's folder. |
| 643 | 5. After runScript() finishes, we will have to be back in the caller's folder, |
| 644 | so that the use of file names in the caller after runScript() |
| 645 | will be interpreted relative to the caller's folder again. |
| 646 | */ |
| 647 | {// scope |
| 648 | autoMelderFileSetCurrentFoldercxx . . $ autoMelderFileSetCurrentFolder# foldercxx . . $ autoMelderFileSetCurrentFolder#autoMelderFileSetCurrentFolder(1145552d769d7b5d). (& file); // so that callee-relative file names can be used for including include files |
| 649 | Melder_includeIncludeFilescxx . . $ Melder_includeIncludeFiles(2d5e149ff849c92b). (& text); |
| 650 | } // back to the default directory of the caller |
| 651 | autoInterpretercxx . . $ autoInterpreter# interpreter = Interpreter_createFromEnvironmentcxx . . $ Interpreter_createFromEnvironment(2a446a9b6f15a803). ( |
| 652 | interpreterStack, |
| 653 | optionalInterpreterOwningEditor, |
| 654 | & file |
| 655 | ); |
| 656 | Interpreter_readParameterscxx . . $ Interpreter_readParameters(9dd4ed1655057857). (interpreter.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), text.getcxx . . $ _autostring#get(5a2a78a048fb49a8).()); // TODO: should become a field of structInterpreter |
| 657 | autoMelderReadTextcxx . . $ autoMelderReadText# readText = MelderReadText_createFromTextcxx . . $ MelderReadText_createFromText(ec22451ee8ecfd96). (textcxx . . $ _autostring#_autostring(39021ecceedcc7d2)..movecxx . . $ _autostring#move(bd43c759570f178f).()); |
| 658 | autoManPagescxx . . $ autoManPages# manPages = ManPages_createFromTextcxx . . $ ManPages_createFromText(c494f626560144be). (readText.getcxx . . $ std/unique_ptr#get(ea7391e9eeeaf20e).(), & file); |
| 659 | ManPagecxx . . $ ManPage# firstPage = manPages ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). pagescxx . . $ structManPages#pages..atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).1]; |
| 660 | autoManualcxx . . $ autoManual# manual = Manual_createcxx . . $ Manual_create(639647387c88cb04). (firstPage -> titlecxx . . $ structManPage#title..getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), interpreter.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), manPages.releaseToAmbiguousOwnercxx . . $ autoSomeThing#releaseToAmbiguousOwner(258ee1c9e0a18a5c).(), true, true); |
| 661 | manual.releaseToUsercxx . . $ autoSomeThing#releaseToUser(ced63f7c635d850d). (); |
| 662 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 663 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Notebook ", & file, U" not completed."); // don't refer to 'fileName', because its contents may have changed |
| 664 | } |
| 665 | } |
| 666 | } |
| 667 | |
| 668 | void praat_executeScriptFromCommandLinecxx . . $ praat_executeScriptFromCommandLine(f3d464eb7bbd4ab6). (conststring32cxx . . $ conststring32# fileName, integercxx . . $ integer# argc, char **argv, bool fullTrust) { |
| 669 | static autoInterpreterStackcxx . . $ autoInterpreterStack# interpreterStack = InterpreterStack_createcxx . . $ InterpreterStack_create(91aa183261e4fa82). (Editorcxx . . $ Editor# (nullptr)); |
| 670 | structMelderFilecxx . . $ structMelderFile# file { }; |
| 671 | Melder_relativePathToFilecxx . . $ Melder_relativePathToFile(82691f2ee21fbb13). (fileName, & file); |
| 672 | try { |
| 673 | autostring32cxx . . $ autostring32# text = MelderFile_readTextcxx . . $ MelderFile_readText(2312d39ae70aea26). (& file); |
| 674 | {// scope |
| 675 | autoMelderFileSetCurrentFoldercxx . . $ autoMelderFileSetCurrentFolder# foldercxx . . $ autoMelderFileSetCurrentFolder#autoMelderFileSetCurrentFolder(1145552d769d7b5d). (& file); // so that script-relative file names can be used for including include files |
| 676 | Melder_includeIncludeFilescxx . . $ Melder_includeIncludeFiles(2d5e149ff849c92b). (& text); |
| 677 | } // back to the default directory of the caller |
| 678 | autoInterpretercxx . . $ autoInterpreter# interpreter = Interpreter_createFromEnvironmentcxx . . $ Interpreter_createFromEnvironment(2a446a9b6f15a803). ( |
| 679 | interpreterStack.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), |
| 680 | Editorcxx . . $ Editor# (nullptr), |
| 681 | & file |
| 682 | ); |
| 683 | Interpreter_readParameterscxx . . $ Interpreter_readParameters(9dd4ed1655057857). (interpreter.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), text.getcxx . . $ _autostring#get(5a2a78a048fb49a8).()); |
| 684 | Interpreter_getArgumentsFromCommandLinecxx . . $ Interpreter_getArgumentsFromCommandLine(715a1a3989df8f8a). (interpreter.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), argc, argv); // interpret caller-relative paths for infile/outfile/folder arguments |
| 685 | autoMelderFileSetCurrentFoldercxx . . $ autoMelderFileSetCurrentFolder# foldercxx . . $ autoMelderFileSetCurrentFolder#autoMelderFileSetCurrentFolder(1145552d769d7b5d). (& file); // so that script-relative file names can be used inside the script |
| 686 | Interpreter_rememberScriptcxx . . $ Interpreter_rememberScript(a0c4c87353b136f2). (interpreter.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), & file, fullTrust); |
| 687 | interpreterStack ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). runDowncxx . . $ structInterpreterStack#runDown(f108da249e59f621). (interpretercxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f)..movecxx . . $ autoSomeThing#move(25acc3554b7d1642).(), textcxx . . $ _autostring#_autostring(39021ecceedcc7d2)..movecxx . . $ _autostring#move(bd43c759570f178f).(), false); |
| 688 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 689 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Script ", & file, U" not completed."); // don't refer to 'fileName', because its contents may have changed |
| 690 | } |
| 691 | } |
| 692 | |
| 693 | void praat_executeScriptFromFileNameWithArgumentscxx . . $ praat_executeScriptFromFileNameWithArguments(ff00d524ab0355ec). (conststring32cxx . . $ conststring32# nameAndArguments) { |
| 694 | structMelderFilecxx . . $ structMelderFile# file { }; |
| 695 | try { |
| 696 | char32cxx . . $ char32# path [256]; |
| 697 | const char32cxx . . $ char32# *p, *arguments; |
| 698 | /* |
| 699 | Split into file name and arguments. |
| 700 | */ |
| 701 | p = nameAndArguments; |
| 702 | while (*p == U' ' || *p == U'\t') |
| 703 | p ++; |
| 704 | if (*p == U'\"') { |
| 705 | char32cxx . . $ char32# *q = path; |
| 706 | p ++; // skip quote |
| 707 | while (*p != U'\"' && *p != U'\0') |
| 708 | * q ++ = * p ++; |
| 709 | *q = U'\0'; |
| 710 | arguments = p; |
| 711 | if (*arguments == U'\"') |
| 712 | arguments ++; |
| 713 | if (*arguments == U' ') |
| 714 | arguments ++; |
| 715 | } else { |
| 716 | char32cxx . . $ char32# *q = path; |
| 717 | while (*p != U' ' && *p != U'\0') |
| 718 | * q ++ = * p ++; |
| 719 | *q = U'\0'; |
| 720 | arguments = p; |
| 721 | if (*arguments == U' ') |
| 722 | arguments ++; |
| 723 | } |
| 724 | Melder_relativePathToFilecxx . . $ Melder_relativePathToFile(82691f2ee21fbb13). (path, & file); |
| 725 | |
| 726 | static autoInterpreterStackcxx . . $ autoInterpreterStack# interpreterStack = InterpreterStack_createcxx . . $ InterpreterStack_create(91aa183261e4fa82). (Editorcxx . . $ Editor# (nullptr)); |
| 727 | autostring32cxx . . $ autostring32# text = MelderFile_readTextcxx . . $ MelderFile_readText(2312d39ae70aea26). (& file); |
| 728 | {// scope |
| 729 | autoMelderFileSetCurrentFoldercxx . . $ autoMelderFileSetCurrentFolder# foldercxx . . $ autoMelderFileSetCurrentFolder#autoMelderFileSetCurrentFolder(1145552d769d7b5d). (& file); // so that script-relative file names can be used for including include files |
| 730 | Melder_includeIncludeFilescxx . . $ Melder_includeIncludeFiles(2d5e149ff849c92b). (& text); |
| 731 | } // back to the default directory of the caller |
| 732 | autoInterpretercxx . . $ autoInterpreter# interpreter = Interpreter_createFromEnvironmentcxx . . $ Interpreter_createFromEnvironment(2a446a9b6f15a803). ( |
| 733 | interpreterStack.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), |
| 734 | Editorcxx . . $ Editor# (nullptr), |
| 735 | & file // so that script-relative file names can be used inside the script |
| 736 | ); |
| 737 | if (arguments) { |
| 738 | Interpreter_readParameterscxx . . $ Interpreter_readParameters(9dd4ed1655057857). (interpreter.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), text.getcxx . . $ _autostring#get(5a2a78a048fb49a8).()); |
| 739 | Interpreter_getArgumentsFromStringcxx . . $ Interpreter_getArgumentsFromString(c79bee1e2231f904). (interpreter.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), arguments); // interpret caller-relative paths for infile/outfile/folder arguments |
| 740 | } |
| 741 | Interpreter_rememberScriptcxx . . $ Interpreter_rememberScript(a0c4c87353b136f2). (interpreter.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), & file, false); |
| 742 | interpreterStack ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). runDowncxx . . $ structInterpreterStack#runDown(f108da249e59f621). (interpretercxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f)..movecxx . . $ autoSomeThing#move(25acc3554b7d1642).(), textcxx . . $ _autostring#_autostring(39021ecceedcc7d2)..movecxx . . $ _autostring#move(bd43c759570f178f).(), false); |
| 743 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 744 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Script ", & file, U" not completed."); |
| 745 | } |
| 746 | } |
| 747 | |
| 748 | void praat_runOldExecuteCommandcxx . . $ praat_runOldExecuteCommand(5a4a4121a05e045). (InterpreterStackcxx . . $ InterpreterStack# interpreterStack, conststring32cxx . . $ conststring32# nameAndArguments) { |
| 749 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (interpreterStack); |
| 750 | |
| 751 | char32cxx . . $ char32# path [256]; |
| 752 | const char32cxx . . $ char32# *p, *arguments; |
| 753 | structMelderFilecxx . . $ structMelderFile# file { }; |
| 754 | /* |
| 755 | Split into file name and arguments. |
| 756 | */ |
| 757 | p = nameAndArguments; |
| 758 | while (*p == U' ' || *p == U'\t') |
| 759 | p ++; |
| 760 | if (*p == U'\"') { |
| 761 | char32cxx . . $ char32# *q = path; |
| 762 | p ++; // skip quote |
| 763 | while (*p != U'\"' && *p != U'\0') |
| 764 | * q ++ = * p ++; |
| 765 | *q = U'\0'; |
| 766 | arguments = p; |
| 767 | if (*arguments == U'\"') |
| 768 | arguments ++; |
| 769 | if (*arguments == U' ') |
| 770 | arguments ++; |
| 771 | } else { |
| 772 | char32cxx . . $ char32# *q = path; |
| 773 | while (*p != U' ' && *p != U'\0') |
| 774 | * q ++ = * p ++; |
| 775 | *q = U'\0'; |
| 776 | arguments = p; |
| 777 | if (*arguments == U' ') |
| 778 | arguments ++; |
| 779 | } |
| 780 | Melder_relativePathToFilecxx . . $ Melder_relativePathToFile(82691f2ee21fbb13). (path, & file); |
| 781 | |
| 782 | Interpretercxx . . $ Interpreter# parentInterpreter = interpreterStack -> current_acxx . . $ structInterpreterStack#current_a(f106979d91fbaa9d). (); |
| 783 | if (parentInterpreter -> isInSecondPasscxx . . $ structInterpreter#isInSecondPass.) { |
| 784 | interpreterStack -> resumeNextLevelInSecondPasscxx . . $ structInterpreterStack#resumeNextLevelInSecondPass(49f6e7a06ebc5aa8). (); |
| 785 | } else { |
| 786 | try { |
| 787 | autostring32cxx . . $ autostring32# text = MelderFile_readTextcxx . . $ MelderFile_readText(2312d39ae70aea26). (& file); |
| 788 | {// scope |
| 789 | autoMelderFileSetCurrentFoldercxx . . $ autoMelderFileSetCurrentFolder# foldercxx . . $ autoMelderFileSetCurrentFolder#autoMelderFileSetCurrentFolder(1145552d769d7b5d). (& file); // so that callee-relative file names can be used for including include files |
| 790 | Melder_includeIncludeFilescxx . . $ Melder_includeIncludeFiles(2d5e149ff849c92b). (& text); |
| 791 | } // back to the default directory of the caller |
| 792 | autoInterpretercxx . . $ autoInterpreter# me = Interpreter_createFromEnvironmentcxx . . $ Interpreter_createFromEnvironment(2a446a9b6f15a803). ( |
| 793 | interpreterStack, |
| 794 | Editorcxx . . $ Editor# (nullptr), |
| 795 | & file // so that callee-relative file names can be used inside the script |
| 796 | ); |
| 797 | if (arguments) { |
| 798 | Interpreter_readParameterscxx . . $ Interpreter_readParameters(9dd4ed1655057857). (me.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), text.getcxx . . $ _autostring#get(5a2a78a048fb49a8).()); |
| 799 | Interpreter_getArgumentsFromStringcxx . . $ Interpreter_getArgumentsFromString(c79bee1e2231f904). (me.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), arguments); // interpret caller-relative paths for infile/outfile/folder arguments |
| 800 | } |
| 801 | mycxx . . $ `melder/melder.h:44:9`! textcxx . . $ structInterpreter#text. =cxx . . $ _autostring#`operator=`(f562943cbc4bcf37). text.movecxx . . $ _autostring#move(bd43c759570f178f).(); |
| 802 | Interpreter_rememberScriptcxx . . $ Interpreter_rememberScript(a0c4c87353b136f2). (me.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), & file, ! parentInterpreter -> scriptReferencecxx . . $ structInterpreter#scriptReference. || parentInterpreter -> scriptReferencecxx . . $ structInterpreter#scriptReference. -> trustedcxx . . $ structScript#trusted.); |
| 803 | interpreterStack -> runDowncxx . . $ structInterpreterStack#runDown(f108da249e59f621). (mecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f)..movecxx . . $ autoSomeThing#move(25acc3554b7d1642).(), autostring32cxx . . $ _autostring#_autostring(49f6e7a06ebc5aa8).(), false); // callee-relative file names can be used inside the script |
| 804 | // back to the default directory of the caller |
| 805 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 806 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Script ", & file, U" not completed."); |
| 807 | } |
| 808 | } |
| 809 | } |
| 810 | |
| 811 | extern "C" void praatlib_executeScript (const char *text8) { |
| 812 | static autoInterpreterStackcxx . . $ autoInterpreterStack# interpreterStack = InterpreterStack_createcxx . . $ InterpreterStack_create(91aa183261e4fa82). (Editorcxx . . $ Editor# (nullptr)); // TODO: never from an editor? |
| 813 | try { |
| 814 | autoInterpretercxx . . $ autoInterpreter# interpreter = Interpreter_createFromEnvironmentcxx . . $ Interpreter_createFromEnvironment(2a446a9b6f15a803). ( |
| 815 | interpreterStack.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), |
| 816 | Editorcxx . . $ Editor# (nullptr), |
| 817 | MelderFilecxx . . $ MelderFile# (nullptr) // TODO: look for a file... |
| 818 | ); |
| 819 | autostring32cxx . . $ autostring32# string = Melder_8to32_ecxx . . $ Melder_8to32_e(f01fe69d6ed2498b). (text8); |
| 820 | interpreterStack ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). runDowncxx . . $ structInterpreterStack#runDown(f108da249e59f621). (interpretercxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f)..movecxx . . $ autoSomeThing#move(25acc3554b7d1642).(), stringcxx . . $ _autostring#_autostring(39021ecceedcc7d2)..movecxx . . $ _autostring#move(bd43c759570f178f).(), false); |
| 821 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 822 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Script not completed."); |
| 823 | } |
| 824 | } |
| 825 | |
| 826 | void praat_executeScriptFromTextcxx . . $ praat_executeScriptFromText(ff00d524ab0355ec). (conststring32cxx . . $ conststring32# text) { |
| 827 | static autoInterpreterStackcxx . . $ autoInterpreterStack# interpreterStack = InterpreterStack_createcxx . . $ InterpreterStack_create(91aa183261e4fa82). (Editorcxx . . $ Editor# (nullptr)); // never from an editor (last checked 2026-02-01) |
| 828 | try { |
| 829 | autoInterpretercxx . . $ autoInterpreter# interpreter = Interpreter_createFromEnvironmentcxx . . $ Interpreter_createFromEnvironment(2a446a9b6f15a803). ( |
| 830 | interpreterStack.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), |
| 831 | Editorcxx . . $ Editor# (nullptr), // never from an editor (last checked 2026-02-01) |
| 832 | MelderFilecxx . . $ MelderFile# (nullptr) |
| 833 | ); |
| 834 | Melder_getCurrentFoldercxx . . $ Melder_getCurrentFolder(63f38d3b6b86d1dc). (& interpreter ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). workingDirectorycxx . . $ structInterpreter#workingDirectory.); |
| 835 | interpreterStack ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). emptyAllcxx . . $ structInterpreterStack#emptyAll(49f6e7a06ebc5aa8). (); |
| 836 | //Interpreter_rememberScript (interpreter.get(), & file, true); // will be OR-ed |
| 837 | interpreterStack ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). runDowncxx . . $ structInterpreterStack#runDown(f108da249e59f621). (interpretercxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f)..movecxx . . $ autoSomeThing#move(25acc3554b7d1642).(), Melder_dupcxx . . $ Melder_dup(87bf156b1f548402). (text), false); |
| 838 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 839 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Script not completed."); |
| 840 | } |
| 841 | } |
| 842 | |
| 843 | static void secondPassThroughScriptcxx . . $ secondPassThroughScript(744a0abd3c8513c). (UiFormcxx . . $ UiForm# sendingForm, integercxx . . $ integer# /* narg */, Stackelcxx . . $ Stackel# /* args */, |
| 844 | conststring32cxx . . $ conststring32# /* sendingString_dummy */, Interpretercxx . . $ Interpreter# /* interpreter_dummy */, |
| 845 | conststring32cxx . . $ conststring32# /* invokingButtonTitle */, bool /* modified */, void * /* closure */, Editorcxx . . $ Editor# optionalInterpreterOwningEditor) |
| 846 | { |
| 847 | static autoInterpreterStackcxx . . $ autoInterpreterStack# interpreterStackcxx . . $ autoSomeThing#autoSomeThing(49f6e7a06ebc5aa8).; |
| 848 | interpreterStack =cxx . . $ autoSomeThing#`operator=`(80cc59814f7161e8). InterpreterStack_createcxx . . $ InterpreterStack_create(91aa183261e4fa82). (optionalInterpreterOwningEditor); // each time anew |
| 849 | structMelderFilecxx . . $ structMelderFile# file { }; |
| 850 | Melder_pathToFilecxx . . $ Melder_pathToFile(82691f2ee21fbb13). (sendingForm -> scriptFilePathcxx . . $ structUiForm#scriptFilePath..getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), & file); |
| 851 | autostring32cxx . . $ autostring32# text = MelderFile_readTextcxx . . $ MelderFile_readText(2312d39ae70aea26). (& file); |
| 852 | {// scope |
| 853 | autoMelderFileSetCurrentFoldercxx . . $ autoMelderFileSetCurrentFolder# foldercxx . . $ autoMelderFileSetCurrentFolder#autoMelderFileSetCurrentFolder(1145552d769d7b5d). (& file); |
| 854 | Melder_includeIncludeFilescxx . . $ Melder_includeIncludeFiles(2d5e149ff849c92b). (& text); |
| 855 | } |
| 856 | autoInterpretercxx . . $ autoInterpreter# interpreter = Interpreter_createFromEnvironmentcxx . . $ Interpreter_createFromEnvironment(2a446a9b6f15a803). ( |
| 857 | interpreterStack.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), |
| 858 | optionalInterpreterOwningEditor, |
| 859 | & file |
| 860 | ); |
| 861 | Interpreter_readParameterscxx . . $ Interpreter_readParameters(9dd4ed1655057857). (interpreter.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), text.getcxx . . $ _autostring#get(5a2a78a048fb49a8).()); |
| 862 | Interpreter_getArgumentsFromDialogcxx . . $ Interpreter_getArgumentsFromDialog(d4b141834b28b228). (interpreter.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), sendingForm); |
| 863 | autoPraatBackgroundcxx . . $ autoPraatBackground# backgroundcxx . . $ autoPraatBackground#autoPraatBackground(49f6e7a06ebc5aa8).; |
| 864 | interpreterStack ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). emptyAllcxx . . $ structInterpreterStack#emptyAll(49f6e7a06ebc5aa8). (); |
| 865 | Interpreter_rememberScriptcxx . . $ Interpreter_rememberScript(a0c4c87353b136f2). (interpreter.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), & file, false); // will be OR-ed |
| 866 | interpreterStack ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). runDowncxx . . $ structInterpreterStack#runDown(f108da249e59f621). (interpretercxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f)..movecxx . . $ autoSomeThing#move(25acc3554b7d1642).(), textcxx . . $ _autostring#_autostring(39021ecceedcc7d2)..movecxx . . $ _autostring#move(bd43c759570f178f).(), false); |
| 867 | } |
| 868 | |
| 869 | static void firstPassThroughScriptcxx . . $ firstPassThroughScript(ef6f5db8e45e165). (MelderFilecxx . . $ MelderFile# file, Editorcxx . . $ Editor# optionalInterpreterOwningEditor, EditorCommandcxx . . $ EditorCommand# optionalCommand, bool fullTrust) { |
| 870 | static autoInterpreterStackcxx . . $ autoInterpreterStack# interpreterStackcxx . . $ autoSomeThing#autoSomeThing(49f6e7a06ebc5aa8).; |
| 871 | //UiPause_cleanUp (); // TODO: needed? |
| 872 | try { |
| 873 | autostring32cxx . . $ autostring32# text = MelderFile_readTextcxx . . $ MelderFile_readText(2312d39ae70aea26). (file); |
| 874 | /* |
| 875 | We switch between default directories no fewer than four times: |
| 876 | 1. runScript() tends to be called from a script that we call the "caller"; |
| 877 | when we enter runScript(), the default directory is the caller's folder, |
| 878 | as was appropriate for the use of file names in the caller before runScript(), |
| 879 | which had to be interpreted relative to the caller's folder. |
| 880 | 2. runScript() will call a script that we call the "callee"; |
| 881 | include files have to be included from the callee's folder. |
| 882 | 3. For expanding any infile/outfile/folder arguments to runScript(), |
| 883 | we have to be back in the caller's folder. |
| 884 | 4. Inside the callee, file names will have to be interpreted relative to the callee's folder. |
| 885 | 5. After runScript() finishes, we will have to be back in the caller's folder, |
| 886 | so that the use of file names in the caller after runScript() |
| 887 | will be interpreted relative to the caller's folder again. |
| 888 | */ |
| 889 | {// scope |
| 890 | autoMelderFileSetCurrentFoldercxx . . $ autoMelderFileSetCurrentFolder# foldercxx . . $ autoMelderFileSetCurrentFolder#autoMelderFileSetCurrentFolder(1145552d769d7b5d). (file); // so that callee-relative file names can be used for including include files |
| 891 | Melder_includeIncludeFilescxx . . $ Melder_includeIncludeFiles(2d5e149ff849c92b). (& text); |
| 892 | } // back to the default directory of the caller |
| 893 | |
| 894 | interpreterStack =cxx . . $ autoSomeThing#`operator=`(80cc59814f7161e8). InterpreterStack_createcxx . . $ InterpreterStack_create(91aa183261e4fa82). (optionalInterpreterOwningEditor); |
| 895 | autoInterpretercxx . . $ autoInterpreter# interpreter = Interpreter_createFromEnvironmentcxx . . $ Interpreter_createFromEnvironment(2a446a9b6f15a803). ( |
| 896 | interpreterStack.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), |
| 897 | optionalInterpreterOwningEditor, |
| 898 | file // so that callee-relative file names can be used inside the script |
| 899 | ); |
| 900 | Interpreter_rememberScriptcxx . . $ Interpreter_rememberScript(a0c4c87353b136f2). (interpreter.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), file, fullTrust); // this is early, but possible here because the name of the script cannot change (and NEEDED for "passing" to second pass) |
| 901 | |
| 902 | const integercxx . . $ integer# numberOfParameters = Interpreter_readParameterscxx . . $ Interpreter_readParameters(9dd4ed1655057857). (interpreter.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), text.getcxx . . $ _autostring#get(5a2a78a048fb49a8).()); |
| 903 | if (numberOfParameters > 0) { |
| 904 | const GuiWindowcxx . . $ GuiWindow# parentShell = ( optionalInterpreterOwningEditor ? optionalInterpreterOwningEditor -> windowFormcxx . . $ structEditor#windowForm. : theCurrentPraatApplicationcxx . . $ theCurrentPraatApplication. -> topShellcxx . . $ structPraatApplication#topShell. ); |
| 905 | autoUiFormcxx . . $ autoUiForm# form = Interpreter_createFormcxx . . $ Interpreter_createForm(cb75ceafc4a9bd55). (interpreter.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), parentShell, optionalInterpreterOwningEditor, |
| 906 | MelderFile_peekPathcxx . . $ MelderFile_peekPath(d9f043369fa9b55b). (file), secondPassThroughScriptcxx . . $ secondPassThroughScript(744a0abd3c8513c)., nullptr, false); |
| 907 | UiForm_docxx . . $ UiForm_do(c04b2c306b4dc6f4). (form.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), false); |
| 908 | if (optionalCommand) { |
| 909 | optionalCommand -> d_uiformcxx . . $ structEditorCommand#d_uiform. =cxx . . $ autoSomeThing#`operator=`(80cc59814f7161e8). form.movecxx . . $ autoSomeThing#move(25acc3554b7d1642).(); |
| 910 | } else { |
| 911 | UiForm_destroyWhenUnmanagedcxx . . $ UiForm_destroyWhenUnmanaged(b4388889c5fb10c0). (form.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).()); |
| 912 | form. releaseToUsercxx . . $ autoSomeThing#releaseToUser(ced63f7c635d850d).(); |
| 913 | } |
| 914 | } else { |
| 915 | {// scope |
| 916 | autoPraatBackgroundcxx . . $ autoPraatBackground# backgroundcxx . . $ autoPraatBackground#autoPraatBackground(49f6e7a06ebc5aa8).; |
| 917 | interpreterStack ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). emptyAllcxx . . $ structInterpreterStack#emptyAll(49f6e7a06ebc5aa8). (); |
| 918 | //Interpreter_rememberScript (interpreter.get(), file, false); // superfluous |
| 919 | interpreterStack ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). runDowncxx . . $ structInterpreterStack#runDown(f108da249e59f621). (interpretercxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f)..movecxx . . $ autoSomeThing#move(25acc3554b7d1642).(), textcxx . . $ _autostring#_autostring(39021ecceedcc7d2)..movecxx . . $ _autostring#move(bd43c759570f178f).(), false); |
| 920 | } |
| 921 | } |
| 922 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 923 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Script ", file, U" not completed."); |
| 924 | } |
| 925 | } |
| 926 | |
| 927 | void DO_RunTheScriptFromAnyAddedMenuCommandcxx . . $ DO_RunTheScriptFromAnyAddedMenuCommand(744a0abd3c8513c). (UiFormcxx . . $ UiForm# /* sendingForm_dummy */, integercxx . . $ integer# /* narg */, Stackelcxx . . $ Stackel# /* args */, |
| 928 | conststring32cxx . . $ conststring32# scriptPath, Interpretercxx . . $ Interpreter# /* interpreter */, |
| 929 | conststring32cxx . . $ conststring32# /* invokingButtonTitle */, bool /* modified */, void *, Editorcxx . . $ Editor# optionalInterpreterOwningEditor) |
| 930 | { |
| 931 | structMelderFilecxx . . $ structMelderFile# file { }; |
| 932 | Melder_relativePathToFilecxx . . $ Melder_relativePathToFile(82691f2ee21fbb13). (scriptPath, & file); |
| 933 | firstPassThroughScriptcxx . . $ firstPassThroughScript(ef6f5db8e45e165). (& file, optionalInterpreterOwningEditor, nullptr, false); |
| 934 | } |
| 935 | |
| 936 | void praat_runScriptWithFormcxx . . $ praat_runScriptWithForm(7004b68cc6c23ea2). (conststring32cxx . . $ conststring32# fileName, bool fullTrust) { |
| 937 | structMelderFilecxx . . $ structMelderFile# file { }; |
| 938 | Melder_relativePathToFilecxx . . $ Melder_relativePathToFile(82691f2ee21fbb13). (fileName, & file); |
| 939 | firstPassThroughScriptcxx . . $ firstPassThroughScript(ef6f5db8e45e165). (& file, nullptr, nullptr, fullTrust); |
| 940 | } |
| 941 | |
| 942 | void praat_executeScriptFromEditorCommandcxx . . $ praat_executeScriptFromEditorCommand(d13209d459650523). (Editorcxx . . $ Editor# interpreterOwningEditor, EditorCommandcxx . . $ EditorCommand# command, conststring32cxx . . $ conststring32# scriptPath) { |
| 943 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (interpreterOwningEditor); |
| 944 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (command); |
| 945 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (command -> d_editor == interpreterOwningEditor); |
| 946 | structMelderFilecxx . . $ structMelderFile# file { }; |
| 947 | Melder_relativePathToFilecxx . . $ Melder_relativePathToFile(82691f2ee21fbb13). (scriptPath, & file); |
| 948 | firstPassThroughScriptcxx . . $ firstPassThroughScript(ef6f5db8e45e165). (& file, interpreterOwningEditor, command, false); |
| 949 | } |
| 950 | |
| 951 | /* End of file praat_script.cpp */ |