Manual.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539
  1. /* Manual.cpp
  2. *
  3. * Copyright (C) 1996-2018 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 2 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. #include <ctype.h>
  19. #include "Manual.h"
  20. #include "Printer.h"
  21. #include "machine.h"
  22. #include "site.h"
  23. #include <time.h>
  24. #include "EditorM.h"
  25. #include "praat_script.h"
  26. #include "praatP.h"
  27. Thing_implement (Manual, HyperPage, 0);
  28. /* Remaining BUGS: HTML writer does not recognize "\s{". */
  29. #define SEARCH_PAGE 0
  30. static const conststring32 month [] =
  31. { U"", U"January", U"February", U"March", U"April", U"May", U"June",
  32. U"July", U"August", U"September", U"October", U"November", U"December" };
  33. static void menu_cb_writeOneToHtmlFile (Manual me, EDITOR_ARGS_FORM) {
  34. EDITOR_FORM_SAVE (U"Save as HTML file", nullptr)
  35. ManPages manPages = (ManPages) my data;
  36. autoMelderString buffer;
  37. MelderString_copy (& buffer, manPages -> pages.at [my path] -> title.get());
  38. char32 *p = buffer.string;
  39. while (*p) { if (! isalnum ((int) *p) && *p != U'_') *p = U'_'; p ++; }
  40. MelderString_append (& buffer, U".html");
  41. Melder_sprint (defaultName,300, buffer.string);
  42. EDITOR_DO_SAVE
  43. ManPages_writeOneToHtmlFile ((ManPages) my data, my path, file);
  44. EDITOR_END
  45. }
  46. static void menu_cb_writeAllToHtmlDir (Manual me, EDITOR_ARGS_FORM) {
  47. EDITOR_FORM (U"Save all pages as HTML files", nullptr)
  48. TEXTFIELD (directory, U"Directory:", U"")
  49. EDITOR_OK
  50. SET_STRING (directory, Melder_dirToPath (& my rootDirectory))
  51. EDITOR_DO
  52. ManPages_writeAllToHtmlDir ((ManPages) my data, directory);
  53. EDITOR_END
  54. }
  55. static void menu_cb_searchForPageList (Manual me, EDITOR_ARGS_FORM) {
  56. EDITOR_FORM (U"Search for page", nullptr)
  57. static ManPages manPages;
  58. static conststring32vector pages;
  59. manPages = (ManPages) my data;
  60. pages = ManPages_getTitles (manPages);
  61. LIST (page, U"Page", pages, 1)
  62. EDITOR_OK
  63. EDITOR_DO
  64. HyperPage_goToPage_i (me, page);
  65. EDITOR_END
  66. }
  67. void structManual :: v_draw () {
  68. ManPages manPages = (ManPages) our data;
  69. ManPage page;
  70. #if motif
  71. Graphics_clearWs (our graphics.get());
  72. #endif
  73. if (our path == SEARCH_PAGE) {
  74. HyperPage_pageTitle (this, U"Best matches");
  75. HyperPage_intro (this, U"The best matches to your query seem to be:");
  76. for (int i = 1; i <= our numberOfMatches; i ++) {
  77. char32 link [300];
  78. page = manPages -> pages.at [matches [i]];
  79. Melder_sprint (link,300, U"• @@", page -> title.get());
  80. HyperPage_listItem (this, link);
  81. }
  82. return;
  83. }
  84. page = manPages -> pages.at [path];
  85. if (! our paragraphs) return;
  86. HyperPage_pageTitle (this, page -> title.get());
  87. for (ManPage_Paragraph paragraph = & page -> paragraphs [0]; (int) paragraph -> type != 0; paragraph ++) {
  88. switch (paragraph -> type) {
  89. case kManPage_type::INTRO: HyperPage_intro (this, paragraph -> text); break;
  90. case kManPage_type::ENTRY: HyperPage_entry (this, paragraph -> text); break;
  91. case kManPage_type::NORMAL: HyperPage_paragraph (this, paragraph -> text); break;
  92. case kManPage_type::LIST_ITEM: HyperPage_listItem (this, paragraph -> text); break;
  93. case kManPage_type::TAG: HyperPage_listTag (this, paragraph -> text); break;
  94. case kManPage_type::DEFINITION: HyperPage_definition (this, paragraph -> text); break;
  95. case kManPage_type::CODE: HyperPage_code (this, paragraph -> text); break;
  96. case kManPage_type::PROTOTYPE: HyperPage_prototype (this, paragraph -> text); break;
  97. case kManPage_type::FORMULA: HyperPage_formula (this, paragraph -> text); break;
  98. case kManPage_type::PICTURE: HyperPage_picture (this, paragraph -> width,
  99. paragraph -> height, paragraph -> draw); break;
  100. case kManPage_type::SCRIPT: HyperPage_script (this, paragraph -> width,
  101. paragraph -> height, paragraph -> text); break;
  102. case kManPage_type::LIST_ITEM1: HyperPage_listItem1 (this, paragraph -> text); break;
  103. case kManPage_type::LIST_ITEM2: HyperPage_listItem2 (this, paragraph -> text); break;
  104. case kManPage_type::LIST_ITEM3: HyperPage_listItem3 (this, paragraph -> text); break;
  105. case kManPage_type::TAG1: HyperPage_listTag1 (this, paragraph -> text); break;
  106. case kManPage_type::TAG2: HyperPage_listTag2 (this, paragraph -> text); break;
  107. case kManPage_type::TAG3: HyperPage_listTag3 (this, paragraph -> text); break;
  108. case kManPage_type::DEFINITION1: HyperPage_definition1 (this, paragraph -> text); break;
  109. case kManPage_type::DEFINITION2: HyperPage_definition2 (this, paragraph -> text); break;
  110. case kManPage_type::DEFINITION3: HyperPage_definition3 (this, paragraph -> text); break;
  111. case kManPage_type::CODE1: HyperPage_code1 (this, paragraph -> text); break;
  112. case kManPage_type::CODE2: HyperPage_code2 (this, paragraph -> text); break;
  113. case kManPage_type::CODE3: HyperPage_code3 (this, paragraph -> text); break;
  114. case kManPage_type::CODE4: HyperPage_code4 (this, paragraph -> text); break;
  115. case kManPage_type::CODE5: HyperPage_code5 (this, paragraph -> text); break;
  116. default: break;
  117. }
  118. }
  119. if (ManPages_uniqueLinksHither (manPages, our path)) {
  120. integer ilink, jlink, lastParagraph = 0;
  121. bool goAhead = true;
  122. while ((int) page -> paragraphs [lastParagraph]. type != 0) lastParagraph ++;
  123. if (lastParagraph > 0) {
  124. conststring32 text = page -> paragraphs [lastParagraph - 1]. text;
  125. if (! text || text [0] == U'\0' || text [str32len (text) - 1] != U':') {
  126. if (our printing && our suppressLinksHither)
  127. goAhead = false;
  128. else
  129. HyperPage_entry (this, U"Links to this page");
  130. }
  131. }
  132. if (goAhead) for (ilink = 1; ilink <= page -> nlinksHither; ilink ++) {
  133. integer link = page -> linksHither [ilink];
  134. bool alreadyShown = false;
  135. for (jlink = 1; jlink <= page -> nlinksThither; jlink ++)
  136. if (page -> linksThither [jlink] == link)
  137. alreadyShown = true;
  138. if (! alreadyShown) {
  139. conststring32 title = manPages -> pages.at [page -> linksHither [ilink]] -> title.get();
  140. char32 linkText [304];
  141. Melder_sprint (linkText, 304, U"@@", title, U"@");
  142. HyperPage_listItem (this, linkText);
  143. }
  144. }
  145. }
  146. if (! our printing && page -> date) {
  147. char32 signature [100];
  148. integer date = page -> date;
  149. int imonth = date % 10000 / 100;
  150. if (imonth < 0 || imonth > 12) imonth = 0;
  151. Melder_sprint (signature,100,
  152. U"© ", str32equ (page -> author.get(), U"ppgb") ? U"Paul Boersma" :
  153. str32equ (page -> author.get(), U"djmw") ? U"David Weenink" : page -> author.get(),
  154. U", ", date % 100,
  155. U" ", month [imonth],
  156. U" ", date / 10000);
  157. HyperPage_any (this, U"", our p_font, our p_fontSize, 0, 0.0,
  158. 0.0, 0.0, 0.1, 0.1, HyperPage_ADD_BORDER);
  159. HyperPage_any (this, signature, our p_font, our p_fontSize, Graphics_ITALIC, 0.0,
  160. 0.03, 0.0, 0.1, 0.0, 0);
  161. }
  162. }
  163. /********** PRINTING **********/
  164. static void print (void *void_me, Graphics graphics) {
  165. iam (Manual);
  166. ManPages manPages = (ManPages) my data;
  167. integer numberOfPages = manPages -> pages.size, savePage = my path;
  168. my ps = graphics;
  169. Graphics_setDollarSignIsCode (my ps, true);
  170. Graphics_setAtSignIsLink (my ps, true);
  171. my printing = true;
  172. HyperPage_initSheetOfPaper ((HyperPage) me);
  173. for (integer ipage = 1; ipage <= numberOfPages; ipage ++) {
  174. ManPage page = manPages -> pages.at [ipage];
  175. if (my printPagesStartingWith == nullptr ||
  176. Melder_stringMatchesCriterion (page -> title.get(), kMelder_string::STARTS_WITH, my printPagesStartingWith, true))
  177. {
  178. ManPage_Paragraph par;
  179. my path = ipage;
  180. my paragraphs = page -> paragraphs;
  181. my numberOfParagraphs = 0;
  182. par = my paragraphs;
  183. while ((int) (par ++) -> type != 0) my numberOfParagraphs ++;
  184. my currentPageTitle = Melder_dup_f (page -> title.get());
  185. my v_goToPage_i (ipage);
  186. my v_draw ();
  187. my v_goToPage_i (savePage);
  188. }
  189. }
  190. my printing = false;
  191. my printPagesStartingWith = nullptr;
  192. }
  193. static void menu_cb_printRange (Manual me, EDITOR_ARGS_FORM) {
  194. EDITOR_FORM (U"Print range", nullptr)
  195. SENTENCE (leftOrInsideHeader, U"Left or inside header", U"")
  196. SENTENCE (middleHeader, U"Middle header", U"")
  197. SENTENCE (rightOrOutsideHeader, U"Right or outside header", U"Manual")
  198. SENTENCE (leftOrInsideFooter, U"Left or inside footer", U"")
  199. SENTENCE (middleFooter, U"Middle footer", U"")
  200. SENTENCE (rightOrOutsideFooter, U"Right or outside footer", U"")
  201. BOOLEAN (mirrorEvenOddHeaders, U"Mirror even/odd headers", true)
  202. TEXTFIELD (printAllPagesWhoseTitleStartsWith, U"Print all pages whose title starts with:", U"Intro")
  203. INTEGER (firstPageNumber, U"First page number", U"1")
  204. BOOLEAN (suppressLinksToThisPage, U"Suppress \"Links to this page\"", false)
  205. EDITOR_OK
  206. ManPages manPages = (ManPages) my data;
  207. time_t today = time (nullptr);
  208. char dateA [50];
  209. #ifdef UNIX
  210. struct tm *tm = localtime (& today);
  211. strftime (dateA, 50, "%B %e, %Y", tm);
  212. #else
  213. strcpy (dateA, ctime (& today));
  214. #endif
  215. autostring32 date = Melder_8to32 (dateA);
  216. char32 *newline = str32chr (date.get(), U'\n');
  217. if (newline)
  218. *newline = U'\0';
  219. SET_STRING (leftOrInsideHeader, date.get())
  220. SET_STRING (rightOrOutsideHeader, my name.get())
  221. if (my d_printingPageNumber) SET_INTEGER (firstPageNumber, my d_printingPageNumber + 1)
  222. if (my path >= 1 && my path <= manPages -> pages.size) {
  223. ManPage page = manPages -> pages.at [my path];
  224. SET_STRING (printAllPagesWhoseTitleStartsWith, page -> title.get());
  225. }
  226. EDITOR_DO
  227. my insideHeader = leftOrInsideHeader;
  228. my middleHeader = middleHeader;
  229. my outsideHeader = rightOrOutsideHeader;
  230. my insideFooter = leftOrInsideFooter;
  231. my middleFooter = middleFooter;
  232. my outsideFooter = rightOrOutsideFooter;
  233. my mirror = mirrorEvenOddHeaders;
  234. my printPagesStartingWith = printAllPagesWhoseTitleStartsWith;
  235. my d_printingPageNumber = firstPageNumber;
  236. my suppressLinksHither = suppressLinksToThisPage;
  237. Printer_print (print, me);
  238. EDITOR_END
  239. }
  240. /********** SEARCHING **********/
  241. static double *goodnessOfMatch;
  242. static double searchToken (ManPages me, integer ipage, char32 *token) {
  243. double goodness = 0.0;
  244. ManPage page = my pages.at [ipage];
  245. struct structManPage_Paragraph *par = & page -> paragraphs [0];
  246. if (! token [0]) return 1.0;
  247. /*
  248. * Try to find a match in the title, case-insensitively.
  249. */
  250. static MelderString buffer { };
  251. MelderString_copy (& buffer, page -> title.get());
  252. for (char32 *p = & buffer.string [0]; *p != U'\0'; p ++) *p = Melder_toLowerCase (*p);
  253. if (str32str (buffer.string, token)) {
  254. goodness += 300.0; // lots of points for a match in the title!
  255. if (str32equ (buffer.string, token))
  256. goodness += 10000.0; // even more points for an exact match!
  257. }
  258. /*
  259. * Try to find a match in the paragraphs, case-insensitively.
  260. */
  261. while ((int) par -> type != 0) {
  262. if (par -> text) {
  263. char32 *ptoken;
  264. MelderString_copy (& buffer, par -> text);
  265. for (char32 *p = & buffer.string [0]; *p != '\0'; p ++) *p = Melder_toLowerCase (*p);
  266. ptoken = str32str (buffer.string, token);
  267. if (ptoken) {
  268. goodness += 10.0; // ten points for every paragraph with a match!
  269. if (str32str (ptoken + str32len (token), token)) {
  270. goodness += 1.0; // one point for every second occurrence in a paragraph!
  271. }
  272. }
  273. }
  274. par ++;
  275. }
  276. return goodness;
  277. }
  278. static void search (Manual me, conststring32 query) {
  279. ManPages manPages = (ManPages) my data;
  280. integer numberOfPages = manPages -> pages.size;
  281. static MelderString searchText { };
  282. MelderString_copy (& searchText, query);
  283. for (char32 *p = & searchText.string [0]; *p != U'\0'; p ++) {
  284. if (*p == U'\n') *p = U' ';
  285. *p = Melder_toLowerCase (*p);
  286. }
  287. if (! goodnessOfMatch)
  288. goodnessOfMatch = NUMvector <double> (1, numberOfPages);
  289. for (integer ipage = 1; ipage <= numberOfPages; ipage ++) {
  290. char32 *token = searchText.string;
  291. goodnessOfMatch [ipage] = 1.0;
  292. for (;;) {
  293. char32 *space = str32chr (token, U' ');
  294. if (space) *space = U'\0';
  295. goodnessOfMatch [ipage] *= searchToken (manPages, ipage, token);
  296. if (! space) break;
  297. *space = U' '; // restore
  298. token = space + 1;
  299. }
  300. }
  301. /*
  302. * Find the 20 best matches.
  303. */
  304. my numberOfMatches = 0;
  305. for (integer imatch = 1; imatch <= 20; imatch ++) {
  306. integer imax = 0;
  307. double max = 0.0;
  308. for (integer ipage = 1; ipage <= numberOfPages; ipage ++) {
  309. if (goodnessOfMatch [ipage] > max) {
  310. max = goodnessOfMatch [ipage];
  311. imax = ipage;
  312. }
  313. }
  314. if (! imax) break;
  315. my matches [++ my numberOfMatches] = imax;
  316. goodnessOfMatch [imax] = 0.0; // skip next time
  317. }
  318. HyperPage_goToPage_i (me, SEARCH_PAGE);
  319. }
  320. void Manual_search (Manual me, conststring32 query) {
  321. GuiText_setString (my searchText, query);
  322. search (me, query);
  323. }
  324. static void gui_button_cb_home (Manual me, GuiButtonEvent /* event */) {
  325. ManPages pages = (ManPages) my data;
  326. integer iHome = ManPages_lookUp (pages, U"Intro");
  327. HyperPage_goToPage_i (me, iHome ? iHome : 1);
  328. }
  329. static void gui_button_cb_record (Manual me, GuiButtonEvent /* event */) {
  330. ManPages manPages = (ManPages) my data;
  331. ManPage manPage = ( my path < 1 ? nullptr : manPages -> pages.at [my path] );
  332. GuiThing_setSensitive (my recordButton, false);
  333. GuiThing_setSensitive (my playButton, false);
  334. GuiThing_setSensitive (my publishButton, false);
  335. #if defined (_WIN32)
  336. GdiFlush ();
  337. #endif
  338. if (! Melder_record (manPage == nullptr ? 1.0 : manPage -> recordingTime)) Melder_flushError ();
  339. GuiThing_setSensitive (my recordButton, true);
  340. GuiThing_setSensitive (my playButton, true);
  341. GuiThing_setSensitive (my publishButton, true);
  342. }
  343. static void gui_button_cb_play (Manual me, GuiButtonEvent /* event */) {
  344. GuiThing_setSensitive (my recordButton, false);
  345. GuiThing_setSensitive (my playButton, false);
  346. GuiThing_setSensitive (my publishButton, false);
  347. #if defined (_WIN32)
  348. GdiFlush ();
  349. #endif
  350. Melder_play ();
  351. GuiThing_setSensitive (my recordButton, true);
  352. GuiThing_setSensitive (my playButton, true);
  353. GuiThing_setSensitive (my publishButton, true);
  354. }
  355. static void gui_button_cb_publish (Manual /* me */, GuiButtonEvent /* event */) {
  356. Melder_publishPlayed ();
  357. }
  358. static void do_search (Manual me) {
  359. autostring32 query = GuiText_getString (my searchText);
  360. search (me, query.get());
  361. }
  362. static void gui_button_cb_search (Manual me, GuiButtonEvent /* event */) {
  363. do_search (me);
  364. }
  365. void structManual :: v_createChildren () {
  366. ManPages pages = (ManPages) our data; // has been installed here by Editor_init ()
  367. our d_hasExtraRowOfTools = pages -> dynamic;
  368. Manual_Parent :: v_createChildren ();
  369. #if defined (macintosh)
  370. #define STRING_SPACING 8
  371. #else
  372. #define STRING_SPACING 2
  373. #endif
  374. int height = Machine_getTextHeight (), y = Machine_getMenuBarHeight () + 4;
  375. our homeButton = GuiButton_createShown (our windowForm, 104, 168, y, y + height,
  376. U"Home", gui_button_cb_home, this, 0);
  377. if (pages -> dynamic) {
  378. our recordButton = GuiButton_createShown (our windowForm, 4, 79, y+height+8, y+height+8 + height,
  379. U"Record", gui_button_cb_record, this, 0);
  380. our playButton = GuiButton_createShown (our windowForm, 85, 160, y+height+8, y+height+8 + height,
  381. U"Play", gui_button_cb_play, this, 0);
  382. our publishButton = GuiButton_createShown (our windowForm, 166, 166 + 175, y+height+8, y+height+8 + height,
  383. U"Copy last played to list", gui_button_cb_publish, this, 0);
  384. }
  385. GuiButton_createShown (our windowForm, 274, 274 + 69, y, y + height,
  386. U"Search:", gui_button_cb_search, this, GuiButton_DEFAULT);
  387. our searchText = GuiText_createShown (our windowForm, 274+69 + STRING_SPACING, 452 + STRING_SPACING - 2, y, y + Gui_TEXTFIELD_HEIGHT, 0);
  388. }
  389. static void menu_cb_help (Manual me, EDITOR_ARGS_DIRECT) { HyperPage_goToPage (me, U"Manual"); }
  390. void structManual :: v_createMenus () {
  391. Manual_Parent :: v_createMenus ();
  392. Editor_addCommand (this, U"File", U"Print manual...", 0, menu_cb_printRange);
  393. Editor_addCommand (this, U"File", U"Save page as HTML file...", 0, menu_cb_writeOneToHtmlFile);
  394. Editor_addCommand (this, U"File", U"Save manual to HTML directory...", 0, menu_cb_writeAllToHtmlDir);
  395. Editor_addCommand (this, U"File", U"-- close --", 0, nullptr);
  396. Editor_addCommand (this, U"Go to", U"Search for page (list)...", 0, menu_cb_searchForPageList);
  397. }
  398. void structManual :: v_createHelpMenuItems (EditorMenu menu) {
  399. Manual_Parent :: v_createHelpMenuItems (menu);
  400. EditorMenu_addCommand (menu, U"Manual help", '?', menu_cb_help);
  401. }
  402. void structManual :: v_defaultHeaders (EditorCommand cmd) {
  403. Manual me = (Manual) cmd -> d_editor;
  404. ManPages manPages = (ManPages) my data;
  405. if (my path) {
  406. char32 string [400];
  407. static const conststring32 shortMonth [] =
  408. { U"Jan", U"Feb", U"Mar", U"Apr", U"May", U"Jun", U"Jul", U"Aug", U"Sep", U"Oct", U"Nov", U"Dec" };
  409. ManPage page = manPages -> pages.at [my path];
  410. integer date = page -> date;
  411. SET_STRING (my outsideHeader, page -> title.get())
  412. SET_STRING (my insideFooter, page -> author.get())
  413. if (date) {
  414. Melder_sprint (string,400, shortMonth [date % 10000 / 100 - 1], U" ", date % 100, U", ", date / 10000);
  415. SET_STRING (my insideHeader, string)
  416. }
  417. }
  418. }
  419. integer structManual :: v_getNumberOfPages () {
  420. ManPages manPages = (ManPages) our data;
  421. return manPages -> pages.size;
  422. }
  423. integer structManual :: v_getCurrentPageNumber () {
  424. return our path ? our path : 1;
  425. }
  426. void structManual :: v_goToPage_i (integer pageNumber) {
  427. ManPages manPages = (ManPages) our data;
  428. if (pageNumber < 1 || pageNumber > manPages -> pages.size) {
  429. if (pageNumber == SEARCH_PAGE) {
  430. our path = SEARCH_PAGE;
  431. our currentPageTitle. reset();
  432. return;
  433. } else Melder_throw (U"Page ", pageNumber, U" not found.");
  434. }
  435. our path = pageNumber;
  436. ManPage page = manPages -> pages.at [path];
  437. our paragraphs = page -> paragraphs;
  438. our numberOfParagraphs = 0;
  439. ManPage_Paragraph par = paragraphs;
  440. while ((int) (par ++) -> type != 0) our numberOfParagraphs ++;
  441. our currentPageTitle = Melder_dup_f (page -> title.get());
  442. }
  443. int structManual :: v_goToPage (conststring32 title) {
  444. ManPages manPages = (ManPages) our data;
  445. if (title [0] == U'\\' && title [1] == U'F' && title [2] == U'I') {
  446. structMelderFile file { };
  447. MelderDir_relativePathToFile (& manPages -> rootDirectory, title + 3, & file);
  448. Melder_recordFromFile (& file);
  449. return -1;
  450. } else if (title [0] == U'\\' && title [1] == U'S' && title [2] == U'C') {
  451. autoMelderSetDefaultDir dir (& manPages -> rootDirectory);
  452. autoPraatBackground background;
  453. try {
  454. autostring32 fileNameWithArguments = Melder_dup (title + 3);
  455. praat_executeScriptFromFileNameWithArguments (fileNameWithArguments.get());
  456. } catch (MelderError) {
  457. Melder_flushError ();
  458. }
  459. return 0;
  460. } else {
  461. integer i = ManPages_lookUp (manPages, title);
  462. if (! i)
  463. Melder_throw (U"Page \"", title, U"\" not found.");
  464. our v_goToPage_i (i);
  465. return 1;
  466. }
  467. }
  468. void Manual_init (Manual me, conststring32 title, Daata data, bool ownData) {
  469. ManPages manPages = (ManPages) data;
  470. integer i;
  471. if ((i = ManPages_lookUp (manPages, title)) == 0)
  472. Melder_throw (U"Page \"", title, U"\" not found.");
  473. my path = i;
  474. ManPage page = manPages -> pages.at [i];
  475. my paragraphs = page -> paragraphs;
  476. my numberOfParagraphs = 0;
  477. ManPage_Paragraph par = my paragraphs;
  478. while ((int) (par ++) -> type != 0) my numberOfParagraphs ++;
  479. char32 windowTitle [101];
  480. if (manPages -> pages.at [1] -> title [0] == U'-') {
  481. Melder_sprint (windowTitle,101, & manPages -> pages.at [1] -> title [1]);
  482. if (windowTitle [str32len (windowTitle) - 1] == U'-') windowTitle [str32len (windowTitle) - 1] = U'\0';
  483. } else {
  484. Melder_sprint (windowTitle,101, U"Manual");
  485. }
  486. my ownData = ownData;
  487. HyperPage_init (me, windowTitle, data);
  488. MelderDir_copy (& manPages -> rootDirectory, & my rootDirectory);
  489. my history [0]. page = Melder_dup_f (title); // BAD
  490. }
  491. autoManual Manual_create (conststring32 title, Daata data, bool ownData) {
  492. try {
  493. autoManual me = Thing_new (Manual);
  494. Manual_init (me.get(), title, data, ownData);
  495. return me;
  496. } catch (MelderError) {
  497. Melder_throw (U"Manual window not created.");
  498. }
  499. }
  500. /* End of file Manual.cpp */