Debian Codegraph @

sys/ManPage.cpp

raw symbols SCIP
1 /* ManPage.cpp
2 *
3 * Copyright (C) 1996-2011,2016,2023-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 "ManPage.h"cxx . . $ `<file>/sys/ManPage.h`/
20 #include "praat.h"cxx . . $ `<file>/sys/praat.h`/
21
22 #include "enums_getText.h"cxx . . $ `<file>/melder/enums_getText.h`/
23 #include "ManPage_enums.h"cxx . . $ `<file>/sys/ManPage_enums.h`/
24 #include "enums_getValue.h"cxx . . $ `<file>/melder/enums_getValue.h`/
25 #include "ManPage_enums.h"cxx . . $ `<file>/sys/ManPage_enums.h`/
26
27 Thing_implementcxx . . $ `sys/Thing.h:65:9`! (ManPage, Thing, 0);
28
29 static autoMelderStringcxx . . $ autoMelderString# *manualInfoProc_stringcxx . . $ manualInfoProc_string.;
30 static void manualInfoProccxx . . $ manualInfoProc(ff00d524ab0355ec). (conststring32cxx . . $ conststring32# infoText) {
31 MelderString_copycxx . . $ MelderString_copy(65be51a793e0ff96). (manualInfoProc_stringcxx . . $ manualInfoProc_string., infoText);
32 // FIXME: this overrides a growing info buffer, which is an O(N^2) algorithm if in a loop
33 }
34
35 void ManPage_runAllChunksToCachecxx . . $ ManPage_runAllChunksToCache(ff13b59e6b589edf). (ManPagecxx . . $ ManPage# me, Interpretercxx . . $ Interpreter# optionalInterpreterReference,
36 const kGraphics_fontcxx . . $ kGraphics_font# font, const double fontSize,
37 PraatApplicationcxx . . $ PraatApplication# praatApplication, PraatObjectscxx . . $ PraatObjects# praatObjects, PraatPicturecxx . . $ PraatPicture# praatPicture,
38 MelderFoldercxx . . $ MelderFolder# rootDirectory
39 ) {
40 theCurrentPraatApplicationcxx . . $ theCurrentPraatApplication. = praatApplication;
41 theCurrentPraatApplicationcxx . . $ theCurrentPraatApplication. -> batchcxx . . $ structPraatApplication#batch. = true; // prevent creation of editor windows
42 theCurrentPraatApplicationcxx . . $ theCurrentPraatApplication. -> topShellcxx . . $ structPraatApplication#topShell. = theForegroundPraatApplicationcxx . . $ theForegroundPraatApplication.. topShellcxx . . $ structPraatApplication#topShell.; // needed for UiForm_create () in dialogs
43 theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. = praatObjects;
44 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (praatObjects -> n == 0);
45 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (praatObjects -> totalSelection == 0);
46 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (praatObjects -> totalBeingCreated == 0);
47 praatObjects -> sequentialUniqueIdOfLatestObjectInListcxx . . $ structPraatObjects#sequentialUniqueIdOfLatestObjectInList. = 0;
48 theCurrentPraatPicturecxx . . $ theCurrentPraatPicture. = praatPicture;
49
50 void praat_actions_showcxx . . $ praat_actions_show(49f6e7a06ebc5aa8). (); // TODO: integrate this better
51 praat_actions_showcxx . . $ praat_actions_show(49f6e7a06ebc5aa8). (); // we have to set the `executable` flags to false, in the global variable `theActions`
52
53 #if 1
54 autoInterpreterStackcxx . . $ autoInterpreterStack# interpreterStack = InterpreterStack_createcxx . . $ InterpreterStack_create(91aa183261e4fa82). (Editorcxx . . $ Editor# (nullptr)); // BUG: overwrites existing stack, which is optionalInterpreterReference's owner
55 interpreterStack ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). interpreterscxx . . $ structInterpreterStack#interpreters. [1] =cxx . . $ autoSomeThing#`operator=`(80cc59814f7161e8). Interpreter_createFromEnvironmentcxx . . $ Interpreter_createFromEnvironment(2a446a9b6f15a803). (interpreterStack.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), Editorcxx . . $ Editor# (nullptr), MelderFilecxx . . $ MelderFile# (nullptr));
56 #else
57 Interpreter interpreterReference;
58 autoInterpreterStack interpreterStack;
59 if (optionalInterpreterReference) {
60 interpreterReference = optionalInterpreterReference;
61 } else {
62 interpreterStack = InterpreterStack_create (Editor (nullptr));
63 interpreterStack -> interpreters [1] = Interpreter_createFromEnvironment (interpreterStack.get(), Editor (nullptr));
64 interpreterReference = interpreterStack -> interpreters [1].get();
65 }
66 #endif
67
68 /*
69 When this page is drawn for the first time,
70 all the script parts have to be run,
71 so that the outputs of drawing and info can be cached.
72 */
73 integercxx . . $ integer# chunkNumber = 0;
74 bool anErrorHasOccurred = false;
75 autostring32cxx . . $ autostring32# theErrorThatOccurredcxx . . $ _autostring#_autostring(49f6e7a06ebc5aa8).;
76 integercxx . . $ integer# errorChunk = 0;
77 for (integercxx . . $ integer# ipar = 1; ipar <= mycxx . . $ `melder/melder.h:44:9`! paragraphscxx . . $ structManPage#paragraphs..sizecxx . . $ autovector#size.; ipar ++) {
78 ManPage_Paragraphcxx . . $ ManPage_Paragraph# paragraph = & mycxx . . $ `melder/melder.h:44:9`! paragraphscxx . . $ structManPage#paragraphs. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).ipar];
79 if (paragraph -> typecxx . . $ structManPage_Paragraph#type. != kManPage_typecxx . . $ kManPage_type#::SCRIPTcxx . . $ kManPage_type#SCRIPT.)
80 continue;
81 chunkNumber += 1;
82 if (paragraph -> cacheGraphicscxx . . $ structManPage_Paragraph#cacheGraphics.)
83 break; // don't run the chunks again
84 /*
85 Divert info text from Info window to Manual window.
86 */
87 autoMelderSetInformationProccxx . . $ autoMelderSetInformationProc# divertcxx . . $ autoMelderSetInformationProc#autoMelderSetInformationProc(f441b548652834d9). (manualInfoProccxx . . $ manualInfoProc(ff00d524ab0355ec).);
88 manualInfoProc_stringcxx . . $ manualInfoProc_string. = & paragraph -> cacheInfocxx . . $ structManPage_Paragraph#cacheInfo.;
89 MelderInfo_opencxx . . $ MelderInfo_open(49f6e7a06ebc5aa8). ();
90 /*
91 Divert graphics from Picture window to Manual window.
92 */
93 paragraph -> cacheGraphicscxx . . $ structManPage_Paragraph#cacheGraphics. =cxx . . $ autoSomeThing#`operator=`(80cc59814f7161e8). Graphics_create_screencxx . . $ Graphics_create_screen(47f58b1ed3ae60e8). (nullptr, nullptr, 100);
94 Graphics_startRecordingcxx . . $ Graphics_startRecording(ce6516af4677a324). (paragraph -> cacheGraphicscxx . . $ structManPage_Paragraph#cacheGraphics..getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).());
95 Graphics_setFontcxx . . $ Graphics_setFont(f6e617e53e6c04dc). (paragraph -> cacheGraphicscxx . . $ structManPage_Paragraph#cacheGraphics..getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), font);
96 Graphics_setFontStylecxx . . $ Graphics_setFontStyle(9abe41586e87648d). (paragraph -> cacheGraphicscxx . . $ structManPage_Paragraph#cacheGraphics..getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), 0);
97 Graphics_setFontSizecxx . . $ Graphics_setFontSize(2514a1c07b6be5e2). (paragraph -> cacheGraphicscxx . . $ structManPage_Paragraph#cacheGraphics..getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), fontSize);
98 const double true_width_inches = paragraph -> widthcxx . . $ structManPage_Paragraph#width. * ( paragraph -> widthcxx . . $ structManPage_Paragraph#width. < 0.0 ? -1.0 : fontSize / 12.0 );
99 const double true_height_inches = paragraph -> heightcxx . . $ structManPage_Paragraph#height. * ( paragraph -> heightcxx . . $ structManPage_Paragraph#height. < 0.0 ? -1.0 : fontSize / 12.0 );
100 Graphics_setWrapWidthcxx . . $ Graphics_setWrapWidth(2514a1c07b6be5e2). (paragraph -> cacheGraphicscxx . . $ structManPage_Paragraph#cacheGraphics..getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), 0.0);
101 integercxx . . $ integer# x1DCold, x2DCold, y1DCold, y2DCold;
102 Graphics_inqWsViewportcxx . . $ Graphics_inqWsViewport(17f6d84cadd6c860). (paragraph -> cacheGraphicscxx . . $ structManPage_Paragraph#cacheGraphics..getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), & x1DCold, & x2DCold, & y1DCold, & y2DCold);
103 double x1NDCold, x2NDCold, y1NDCold, y2NDCold;
104 Graphics_inqWsWindowcxx . . $ Graphics_inqWsWindow(962850f2031ce0d0). (paragraph -> cacheGraphicscxx . . $ structManPage_Paragraph#cacheGraphics..getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), & x1NDCold, & x2NDCold, & y1NDCold, & y2NDCold);
105
106 theCurrentPraatPicturecxx . . $ theCurrentPraatPicture. -> graphicscxx . . $ structPraatPicture#graphics. = paragraph -> cacheGraphicscxx . . $ structManPage_Paragraph#cacheGraphics..getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(); // has to draw into HyperPage rather than Picture window
107 theCurrentPraatPicturecxx . . $ theCurrentPraatPicture. -> fontcxx . . $ structPraatPicture#font. = font;
108 theCurrentPraatPicturecxx . . $ theCurrentPraatPicture. -> fontSizecxx . . $ structPraatPicture#fontSize. = fontSize;
109 theCurrentPraatPicturecxx . . $ theCurrentPraatPicture. -> lineTypecxx . . $ structPraatPicture#lineType. = Graphics_DRAWNcxx . . $ `sys/Graphics.h:287:9`!;
110 theCurrentPraatPicturecxx . . $ theCurrentPraatPicture. -> lineWidthcxx . . $ structPraatPicture#lineWidth. = 1.0;
111 theCurrentPraatPicturecxx . . $ theCurrentPraatPicture. -> arrowSizecxx . . $ structPraatPicture#arrowSize. = 1.0;
112 theCurrentPraatPicturecxx . . $ theCurrentPraatPicture. -> speckleSizecxx . . $ structPraatPicture#speckleSize. = 1.0;
113 theCurrentPraatPicturecxx . . $ theCurrentPraatPicture. -> colourcxx . . $ structPraatPicture#colour. =cxx . . $ MelderColour#`operator=`(3ab3c3f6bc5cdda1). Melder_BLACKcxx . . $ Melder_BLACK.;
114 #if 1
115 theCurrentPraatPicturecxx . . $ theCurrentPraatPicture. -> x1NDCcxx . . $ structPraatPicture#x1NDC. = 0.0;
116 theCurrentPraatPicturecxx . . $ theCurrentPraatPicture. -> x2NDCcxx . . $ structPraatPicture#x2NDC. = true_width_inches;
117 theCurrentPraatPicturecxx . . $ theCurrentPraatPicture. -> y1NDCcxx . . $ structPraatPicture#y1NDC. = 0.0;
118 theCurrentPraatPicturecxx . . $ theCurrentPraatPicture. -> y2NDCcxx . . $ structPraatPicture#y2NDC. = true_height_inches;
119
120 Graphics_setViewportcxx . . $ Graphics_setViewport(72bdb7937dbb13da). (paragraph -> cacheGraphicscxx . . $ structManPage_Paragraph#cacheGraphics..getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(),
121 theCurrentPraatPicturecxx . . $ theCurrentPraatPicture. -> x1NDCcxx . . $ structPraatPicture#x1NDC., theCurrentPraatPicturecxx . . $ theCurrentPraatPicture. -> x2NDCcxx . . $ structPraatPicture#x2NDC., theCurrentPraatPicturecxx . . $ theCurrentPraatPicture. -> y1NDCcxx . . $ structPraatPicture#y1NDC., theCurrentPraatPicturecxx . . $ theCurrentPraatPicture. -> y2NDCcxx . . $ structPraatPicture#y2NDC.);
122 #endif
123 Graphics_setWindowcxx . . $ Graphics_setWindow(72bdb7937dbb13da). (paragraph -> cacheGraphicscxx . . $ structManPage_Paragraph#cacheGraphics..getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), 0.0, 1.0, 0.0, 1.0);
124 #if 1
125 integercxx . . $ integer# x1DC, y1DC, x2DC, y2DC;
126 Graphics_WCtoDCcxx . . $ Graphics_WCtoDC(fcc4c7f5705d306f). (paragraph -> cacheGraphicscxx . . $ structManPage_Paragraph#cacheGraphics..getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), 0.0, 0.0, & x1DC, & y2DC);
127 Graphics_WCtoDCcxx . . $ Graphics_WCtoDC(fcc4c7f5705d306f). (paragraph -> cacheGraphicscxx . . $ structManPage_Paragraph#cacheGraphics..getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), 1.0, 1.0, & x2DC, & y1DC);
128 Graphics_resetWsViewportcxx . . $ Graphics_resetWsViewport(4ffe5bb10b2fb6bd). (paragraph -> cacheGraphicscxx . . $ structManPage_Paragraph#cacheGraphics..getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), x1DC, x2DC, y1DC, y2DC);
129 Graphics_setWsWindowcxx . . $ Graphics_setWsWindow(72bdb7937dbb13da). (paragraph -> cacheGraphicscxx . . $ structManPage_Paragraph#cacheGraphics..getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), 0, paragraph -> widthcxx . . $ structManPage_Paragraph#width., 0, paragraph -> heightcxx . . $ structManPage_Paragraph#height.);
130 #endif
131 theCurrentPraatPicturecxx . . $ theCurrentPraatPicture. -> x1NDCcxx . . $ structPraatPicture#x1NDC. = 0.0;
132 theCurrentPraatPicturecxx . . $ theCurrentPraatPicture. -> x2NDCcxx . . $ structPraatPicture#x2NDC. = paragraph -> widthcxx . . $ structManPage_Paragraph#width.;
133 theCurrentPraatPicturecxx . . $ theCurrentPraatPicture. -> y1NDCcxx . . $ structPraatPicture#y1NDC. = 0.0;
134 theCurrentPraatPicturecxx . . $ theCurrentPraatPicture. -> y2NDCcxx . . $ structPraatPicture#y2NDC. = paragraph -> heightcxx . . $ structManPage_Paragraph#height.;
135 Graphics_setViewportcxx . . $ Graphics_setViewport(72bdb7937dbb13da). (paragraph -> cacheGraphicscxx . . $ structManPage_Paragraph#cacheGraphics..getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(),
136 theCurrentPraatPicturecxx . . $ theCurrentPraatPicture. -> x1NDCcxx . . $ structPraatPicture#x1NDC., theCurrentPraatPicturecxx . . $ theCurrentPraatPicture. -> x2NDCcxx . . $ structPraatPicture#x2NDC., theCurrentPraatPicturecxx . . $ theCurrentPraatPicture. -> y1NDCcxx . . $ structPraatPicture#y1NDC., theCurrentPraatPicturecxx . . $ theCurrentPraatPicture. -> y2NDCcxx . . $ structPraatPicture#y2NDC.);
137 if (anErrorHasOccurred) {
138 tracecxx . . $ `melder/melder_debug.h:60:10`! (U"Chunk ", chunkNumber, U" not run, because of an earlier error.");
139 MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"\\#{**ERROR** This code chunk was not run,}\n because an error occurred in an earlier chunk.");
140 MelderInfo_closecxx . . $ MelderInfo_close(49f6e7a06ebc5aa8). ();
141 } else {
142 autoMelderProgressOffcxx . . $ autoMelderProgressOff# progresscxx . . $ autoMelderProgressOff#autoMelderProgressOff(49f6e7a06ebc5aa8).;
143 autoMelderWarningOffcxx . . $ autoMelderWarningOff# nowarncxx . . $ autoMelderWarningOff#autoMelderWarningOff(49f6e7a06ebc5aa8).;
144 autoMelderSaveCurrentFoldercxx . . $ autoMelderSaveCurrentFolder# saveFoldercxx . . $ autoMelderSaveCurrentFolder#autoMelderSaveCurrentFolder(49f6e7a06ebc5aa8).;
145 if (! MelderFolder_isNullcxx . . $ MelderFolder_isNull(f2f3cbeb84a71ab3). (rootDirectory))
146 Melder_setCurrentFoldercxx . . $ Melder_setCurrentFolder(63f38d3b6b86d1dc). (rootDirectory);
147 try {
148 autoMelderStringcxx . . $ autoMelderString# programcxx . . $ autoMelderString#autoMelderString(49f6e7a06ebc5aa8).;
149 MelderString_appendcxx . . $ MelderString_append(65be51a793e0ff96). (& program, paragraph -> textcxx . . $ structManPage_Paragraph#text.);
150 for (integercxx . . $ integer# jpar = 1; jpar <= mycxx . . $ `melder/melder.h:44:9`! paragraphscxx . . $ structManPage#paragraphs..sizecxx . . $ autovector#size.; jpar ++) if (jpar != ipar) {
151 ManPage_Paragraphcxx . . $ ManPage_Paragraph# otherParagraph = & mycxx . . $ `melder/melder.h:44:9`! paragraphscxx . . $ structManPage#paragraphs. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).jpar];
152 if (otherParagraph -> typecxx . . $ structManPage_Paragraph#type. == kManPage_typecxx . . $ kManPage_type#::SCRIPTcxx . . $ kManPage_type#SCRIPT.)
153 if (Melder_startsWithcxx . . $ Melder_startsWith(1652f10ed0f82783). (otherParagraph -> textcxx . . $ structManPage_Paragraph#text., U"\tprocedure ") && Melder_endsWithcxx . . $ Melder_endsWith(1652f10ed0f82783). (otherParagraph -> textcxx . . $ structManPage_Paragraph#text., U"\tendproc\n"))
154 MelderString_appendcxx . . $ MelderString_append(65be51a793e0ff96). (& program, otherParagraph -> textcxx . . $ structManPage_Paragraph#text.);
155 }
156 //Interpreter_rememberNotebook (interpreterStack -> interpreters [1], <#MelderFile notebookFile#>, false);
157 interpreterStack ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). runDowncxx . . $ structInterpreterStack#runDown(f108da249e59f621). (autoInterpretercxx . . $ autoSomeThing#autoSomeThing(49f6e7a06ebc5aa8).(), Melder_dupcxx . . $ Melder_dup(87bf156b1f548402). (program.stringcxx . . $ MelderString#string.), chunkNumber > 1);
158 //interpreterStack -> runDown (interpreterStack -> interpreters [1], Melder_dup (program.string), chunkNumber > 1);
159 } catch (MelderErrorcxx . . $ MelderError#) {
160 anErrorHasOccurred = true;
161 errorChunk = chunkNumber;
162 theErrorThatOccurred =cxx . . $ _autostring#`operator=`(f562943cbc4bcf37). Melder_dupcxx . . $ Melder_dup(87bf156b1f548402). (Melder_getErrorcxx . . $ Melder_getError(1912f6684645c851). ());
163 tracecxx . . $ `melder/melder_debug.h:60:10`! (U"Error in chunk ", chunkNumber, U".");
164 Melder_clearErrorcxx . . $ Melder_clearError(49f6e7a06ebc5aa8). ();
165 MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"\\#{**AN ERROR OCCURRED IN THIS CODE CHUNK:**\n", theErrorThatOccurred.getcxx . . $ _autostring#get(5a2a78a048fb49a8).());
166 MelderInfo_closecxx . . $ MelderInfo_close(49f6e7a06ebc5aa8). ();
167 }
168 }
169 #if 0
170 Graphics_setLineType (paragraph -> cacheGraphics.get(), Graphics_DRAWN);
171 Graphics_setLineWidth (paragraph -> cacheGraphics.get(), 1.0);
172 Graphics_setArrowSize (paragraph -> cacheGraphics.get(), 1.0);
173 Graphics_setSpeckleSize (paragraph -> cacheGraphics.get(), 1.0);
174 Graphics_setColour (paragraph -> cacheGraphics.get(), Melder_BLACK);
175 #endif
176
177 #if 0
178 Graphics_resetWsViewport (paragraph -> cacheGraphics.get(), x1DCold, x2DCold, y1DCold, y2DCold);
179 Graphics_setWsWindow (paragraph -> cacheGraphics.get(), x1NDCold, x2NDCold, y1NDCold, y2NDCold);
180 Graphics_setViewport (paragraph -> cacheGraphics.get(), 0.0, 1.0, 0.0, 1.0);
181 Graphics_setWindow (paragraph -> cacheGraphics.get(), 0.0, 1.0, 0.0, 1.0);
182 Graphics_setTextAlignment (paragraph -> cacheGraphics.get(), Graphics_LEFT, Graphics_BOTTOM);
183 Graphics_stopRecording (paragraph -> cacheGraphics.get());
184 #endif
185 }
186 theCurrentPraatApplicationcxx . . $ theCurrentPraatApplication. = & theForegroundPraatApplicationcxx . . $ theForegroundPraatApplication.;
187 theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. = & theForegroundPraatObjectscxx . . $ theForegroundPraatObjects.;
188 theCurrentPraatPicturecxx . . $ theCurrentPraatPicture. = & theForegroundPraatPicturecxx . . $ theForegroundPraatPicture.;
189 if (anErrorHasOccurred)
190 Melder_flushErrorcxx . . $ Melder_flushError(6298c93241566110). (U"Error in code chunk ", errorChunk, U".\n", theErrorThatOccurred.getcxx . . $ _autostring#get(5a2a78a048fb49a8).());
191 praatObjects -> resetcxx . . $ structPraatObjects#reset(49f6e7a06ebc5aa8).();
192 }
193
194 /* End of file ManPage.cpp */