ManPages.cpp 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901
  1. /* ManPages.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 "ManPages.h"
  20. #include "../kar/longchar.h"
  21. #include "Interpreter.h"
  22. #include "praat.h"
  23. Thing_implement (ManPages, Daata, 0);
  24. #define LONGEST_FILE_NAME 55
  25. static bool isAllowedFileNameCharacter (char32 c) {
  26. return isalnum ((int) c) || c == U'_' || c == U'-' || c == U'+';
  27. }
  28. static bool isSingleWordCharacter (char32 c) {
  29. return isalnum ((int) c) || c == U'_';
  30. }
  31. static integer lookUp_unsorted (ManPages me, conststring32 title);
  32. void structManPages :: v_destroy () noexcept {
  33. /*
  34. A ManPages object is the ambiguous owner of its paragraphs.
  35. */
  36. if (our dynamic) {
  37. for (integer ipage = 1; ipage <= our pages.size; ipage ++) {
  38. ManPage page = our pages.at [ipage];
  39. if (page -> paragraphs) {
  40. ManPage_Paragraph par;
  41. for (par = page -> paragraphs; (int) par -> type != 0; par ++)
  42. Melder_free (par -> text); // not an autostring32, because it can be a string literal (if not dynamic)
  43. NUMvector_free <struct structManPage_Paragraph> (page -> paragraphs, 0);
  44. }
  45. if (ipage == 1) {
  46. NUMvector_free <integer> (page -> linksHither, 1);
  47. NUMvector_free <integer> (page -> linksThither, 1);
  48. }
  49. }
  50. }
  51. ManPages_Parent :: v_destroy ();
  52. }
  53. static conststring32 extractLink (conststring32 text, const char32 *p, char32 *link) {
  54. char32 *to = link, *max = link + 300;
  55. if (! p) p = text;
  56. /*
  57. * Search for next '@' that is not in a backslash sequence.
  58. */
  59. for (;;) {
  60. p = str32chr (p, U'@');
  61. if (! p) return nullptr; // no more '@'
  62. if (p - text <= 0 || (p [-1] != U'\\' && (p - text <= 1 || p [-2] != U'\\'))) break;
  63. p ++;
  64. }
  65. Melder_assert (*p == U'@');
  66. if (p [1] == U'@') {
  67. const char32 *from = p + 2;
  68. while (*from != U'@' && *from != U'|' && *from != U'\0') {
  69. if (to >= max) {
  70. Melder_throw (U"(ManPages::grind:) Link starting with \"@@\" is too long:\n", text);
  71. }
  72. *to ++ = *from ++;
  73. }
  74. if (*from == U'|') { from ++; while (*from != U'@' && *from != U'\0') from ++; }
  75. if (*from) p = from + 1; else p = from; /* Skip '@' but not '\0'. */
  76. } else {
  77. const char32 *from = p + 1;
  78. while (isSingleWordCharacter (*from)) {
  79. if (to >= max) {
  80. Melder_throw (U"(ManPages::grind:) Link starting with \"@@\" is too long:\n", text);
  81. }
  82. *to ++ = *from ++;
  83. }
  84. p = from;
  85. }
  86. *to = U'\0';
  87. return p;
  88. }
  89. static void readOnePage (ManPages me, MelderReadText text) {
  90. autostring32 title;
  91. try {
  92. title = texgetw16 (text);
  93. } catch (MelderError) {
  94. Melder_throw (U"Cannot find page title.");
  95. }
  96. /*
  97. Check whether a page with this title is already present.
  98. */
  99. if (lookUp_unsorted (me, title.get())) {
  100. return;
  101. }
  102. autoManPage autopage = Thing_new (ManPage);
  103. autopage -> title = title.move();
  104. /*
  105. Add the page early, so that lookUp can find it.
  106. */
  107. ManPage page = my pages. addItem_move (autopage.move());
  108. try {
  109. page -> author = texgetw16 (text);
  110. } catch (MelderError) {
  111. Melder_throw (U"Cannot find author.");
  112. }
  113. try {
  114. page -> date = texgetu32 (text);
  115. } catch (MelderError) {
  116. Melder_throw (U"Cannot find date.");
  117. }
  118. try {
  119. page -> recordingTime = texgetr64 (text);
  120. } catch (MelderError) {
  121. Melder_throw (U"Cannot find recording time.");
  122. }
  123. page -> paragraphs = NUMvector <struct structManPage_Paragraph> (0, 500);
  124. ManPage_Paragraph par = & page -> paragraphs [0];
  125. for (;; par ++) {
  126. char32 link [501], fileName [256];
  127. try {
  128. par -> type = (kManPage_type) texgete8 (text, (enum_generic_getValue) kManPage_type_getValue);
  129. } catch (MelderError) {
  130. if (Melder_hasError (U"end of text")) {
  131. Melder_clearError ();
  132. break;
  133. } else {
  134. throw;
  135. }
  136. }
  137. if (par -> type == kManPage_type::SCRIPT) {
  138. par -> width = texgetr64 (text);
  139. par -> height = texgetr64 (text);
  140. }
  141. try {
  142. par -> text = texgetw16 (text).transfer();
  143. } catch (MelderError) {
  144. Melder_throw (U"Cannot find text.");
  145. }
  146. for (const char32 *plink = extractLink (par -> text, nullptr, link); plink != nullptr; plink = extractLink (par -> text, plink, link)) {
  147. /*
  148. * Now, `link' contains the link text, with spaces and all.
  149. * Transform it into a file name.
  150. */
  151. structMelderFile file2 { };
  152. if (link [0] == U'\\' && link [1] == U'F' && link [2] == U'I') {
  153. /*
  154. * A link to a sound file: see if it exists.
  155. */
  156. MelderDir_relativePathToFile (& my rootDirectory, link + 3, & file2);
  157. if (! MelderFile_exists (& file2)) {
  158. Melder_warning (U"Cannot find sound file ", MelderFile_messageName (& file2), U".");
  159. }
  160. } else if (link [0] == U'\\' && link [1] == U'S' && link [2] == U'C') {
  161. /*
  162. * A link to a script: see if it exists.
  163. */
  164. char32 *p = link + 3;
  165. if (*p == '\"') {
  166. char32 *q = fileName;
  167. p ++;
  168. while (*p != U'\"' && *p != U'\0') * q ++ = * p ++;
  169. *q = '\0';
  170. } else {
  171. char32 *q = fileName;
  172. while (*p != U' ' && *p != U'\0') * q ++ = * p ++; // one word, up to the next space
  173. *q = '\0';
  174. }
  175. MelderDir_relativePathToFile (& my rootDirectory, fileName, & file2);
  176. if (! MelderFile_exists (& file2)) {
  177. Melder_warning (U"Cannot find script ", MelderFile_messageName (& file2), U".");
  178. }
  179. my executable = true;
  180. } else {
  181. char32 *q;
  182. /*
  183. * A link to another page: follow it.
  184. */
  185. for (q = link; *q; q ++) if (! isAllowedFileNameCharacter (*q)) *q = U'_';
  186. Melder_sprint (fileName,256, link, U".man");
  187. MelderDir_getFile (& my rootDirectory, fileName, & file2);
  188. try {
  189. autoMelderReadText text2 = MelderReadText_createFromFile (& file2);
  190. try {
  191. readOnePage (me, text2.get());
  192. } catch (MelderError) {
  193. Melder_throw (U"File ", & file2, U".");
  194. }
  195. } catch (MelderError) {
  196. /*
  197. * Second try: with upper case.
  198. */
  199. Melder_clearError ();
  200. link [0] = Melder_toUpperCase (link [0]);
  201. Melder_sprint (fileName,256, link, U".man");
  202. MelderDir_getFile (& my rootDirectory, fileName, & file2);
  203. autoMelderReadText text2 = MelderReadText_createFromFile (& file2);
  204. try {
  205. readOnePage (me, text2.get());
  206. } catch (MelderError) {
  207. Melder_throw (U"File ", & file2, U".");
  208. }
  209. }
  210. }
  211. }
  212. }
  213. ++ par; // room for the last paragraph (because counting starts at 0)
  214. ++ par; // room for the final zero-type paragraph
  215. page -> paragraphs = (ManPage_Paragraph) Melder_realloc (page -> paragraphs, (int64) sizeof (struct structManPage_Paragraph) * (par - page -> paragraphs));
  216. }
  217. void structManPages :: v_readText (MelderReadText text, int /*formatVersion*/) {
  218. our dynamic = true;
  219. MelderDir_copy (& Data_directoryBeingRead, & rootDirectory);
  220. readOnePage (this, text);
  221. }
  222. autoManPages ManPages_create () {
  223. autoManPages me = Thing_new (ManPages);
  224. return me;
  225. }
  226. void ManPages_addPage (ManPages me, conststring32 title, conststring32 author, integer date,
  227. struct structManPage_Paragraph paragraphs [])
  228. {
  229. autoManPage page = Thing_new (ManPage);
  230. page -> title = Melder_dup (title);
  231. page -> paragraphs = & paragraphs [0];
  232. page -> author = Melder_dup (author);
  233. page -> date = date;
  234. my pages. addItem_move (page.move());
  235. }
  236. static int pageCompare (const void *first, const void *second) {
  237. ManPage me = * (ManPage *) first, thee = * (ManPage *) second;
  238. const char32 *p = & my title [0], *q = & thy title [0];
  239. for (;;) {
  240. const char32 plower = Melder_toLowerCase (*p), qlower = Melder_toLowerCase (*q);
  241. if (plower < qlower) return -1;
  242. if (plower > qlower) return 1;
  243. if (plower == U'\0') return str32cmp (my title.get(), thy title.get());
  244. p ++, q ++;
  245. }
  246. return 0; // should not occur
  247. }
  248. static integer lookUp_unsorted (ManPages me, conststring32 title) {
  249. /*
  250. First try to match an unaltered 'title' with the titles of the man pages.
  251. */
  252. for (integer i = 1; i <= my pages.size; i ++) {
  253. ManPage page = my pages.at [i];
  254. if (str32equ (page -> title.get(), title)) return i;
  255. }
  256. /*
  257. If that fails, try to find the upper-case variant.
  258. */
  259. if (Melder_isLowerCaseLetter (title [0])) {
  260. char32 upperTitle [300];
  261. Melder_sprint (upperTitle,300, title);
  262. upperTitle [0] = Melder_toUpperCase (upperTitle [0]);
  263. for (integer i = 1; i <= my pages.size; i ++) {
  264. ManPage page = my pages.at [i];
  265. if (str32equ (page -> title.get(), upperTitle)) return i;
  266. }
  267. }
  268. return 0;
  269. }
  270. static integer lookUp_sorted (ManPages me, conststring32 title) {
  271. static autoManPage dummy;
  272. ManPage *page;
  273. if (! dummy) dummy = Thing_new (ManPage);
  274. dummy -> title = Melder_dup (title);
  275. page = (ManPage *) bsearch (& dummy, & my pages.at [1], integer_to_uinteger (my pages.size), sizeof (ManPage), pageCompare); // noexcept
  276. if (page) return (page - & my pages.at [1]) + 1;
  277. if (Melder_isLowerCaseLetter (title [0]) || Melder_isUpperCaseLetter (title [0])) {
  278. char32 caseSwitchedTitle [300];
  279. Melder_sprint (caseSwitchedTitle,300, title);
  280. caseSwitchedTitle [0] = Melder_isLowerCaseLetter (title [0]) ? Melder_toUpperCase (caseSwitchedTitle [0]) : Melder_toLowerCase (caseSwitchedTitle [0]);
  281. dummy -> title = Melder_dup (caseSwitchedTitle);
  282. page = (ManPage *) bsearch (& dummy, & my pages.at [1], integer_to_uinteger (my pages.size), sizeof (ManPage), pageCompare); // noexcept
  283. if (page) return (page - & my pages.at [1]) + 1;
  284. }
  285. return 0;
  286. }
  287. static void grind (ManPages me) {
  288. integer ndangle = 0, jpage, grandNlinks, ilinkHither, ilinkThither;
  289. integer *grandLinksHither, *grandLinksThither;
  290. qsort (& my pages.at [1], integer_to_uinteger (my pages.size), sizeof (ManPage), pageCompare);
  291. /*
  292. * First pass: count and check links: fill in nlinksHither and nlinksThither.
  293. */
  294. grandNlinks = 0;
  295. for (integer ipage = 1; ipage <= my pages.size; ipage ++) {
  296. ManPage page = my pages.at [ipage];
  297. for (integer ipar = 0; (int) page -> paragraphs [ipar]. type != 0; ipar ++) {
  298. conststring32 text = page -> paragraphs [ipar]. text;
  299. const char32 *p;
  300. char32 link [301];
  301. if (text) for (p = extractLink (text, nullptr, link); p != nullptr; p = extractLink (text, p, link)) {
  302. if (link [0] == U'\\' && ((link [1] == U'F' && link [2] == U'I') || (link [1] == U'S' && link [2] == U'C')))
  303. continue; // ignore "FILE" links
  304. if ((jpage = lookUp_sorted (me, link)) != 0) {
  305. page -> nlinksThither ++;
  306. my pages.at [jpage] -> nlinksHither ++;
  307. grandNlinks ++;
  308. } else {
  309. MelderInfo_writeLine (U"Page \"", page -> title.get(), U"\" contains a dangling link to \"", link, U"\".");
  310. ndangle ++;
  311. }
  312. }
  313. }
  314. }
  315. if (ndangle) {
  316. MelderInfo_close ();
  317. Melder_warning (U"(ManPages::grind:) ", ndangle, U" dangling links encountered. See console window.");
  318. }
  319. /*
  320. * Second pass: allocate memory: fill in linksHither and linksThither.
  321. * Some optimization required: use only two mallocs.
  322. * Forget nlinksHither and nlinksThither.
  323. */
  324. if (grandNlinks == 0) { my ground = true; return; }
  325. if (! (grandLinksHither = NUMvector <integer> (1, grandNlinks)) || ! (grandLinksThither = NUMvector <integer> (1, grandNlinks))) {
  326. Melder_flushError ();
  327. return;
  328. }
  329. ilinkHither = ilinkThither = 0;
  330. for (integer ipage = 1; ipage <= my pages.size; ipage ++) {
  331. ManPage page = my pages.at [ipage];
  332. page -> linksHither = grandLinksHither + ilinkHither;
  333. page -> linksThither = grandLinksThither + ilinkThither;
  334. ilinkHither += page -> nlinksHither;
  335. ilinkThither += page -> nlinksThither;
  336. page -> nlinksHither = 0;
  337. page -> nlinksThither = 0;
  338. }
  339. Melder_assert (ilinkHither == grandNlinks && ilinkThither == grandNlinks);
  340. /*
  341. * Third pass: remember the links: fill in linksThither [1..nlinksThither] and linksHither [1..nlinksHither].
  342. * Rebuild nlinksHither and nlinksThither.
  343. */
  344. for (integer ipage = 1; ipage <= my pages.size; ipage ++) {
  345. ManPage page = my pages.at [ipage];
  346. for (int ipar = 0; (int) page -> paragraphs [ipar]. type != 0; ipar ++) {
  347. conststring32 text = page -> paragraphs [ipar]. text;
  348. const char32 *p;
  349. char32 link [301];
  350. if (text) for (p = extractLink (text, nullptr, link); p != nullptr; p = extractLink (text, p, link)) {
  351. if (link [0] == U'\\' && ((link [1] == U'F' && link [2] == U'I') || (link [1] == U'S' && link [2] == U'C')))
  352. continue; // ignore "FILE" links
  353. if ((jpage = lookUp_sorted (me, link)) != 0) {
  354. bool alreadyPresent = false;
  355. for (int ilink = 1; ilink <= page -> nlinksThither; ilink ++) {
  356. if (page -> linksThither [ilink] == jpage) {
  357. alreadyPresent = true;
  358. break;
  359. }
  360. }
  361. if (! alreadyPresent) {
  362. ManPage otherPage = my pages.at [jpage];
  363. page -> linksThither [++ page -> nlinksThither] = jpage;
  364. otherPage -> linksHither [++ otherPage -> nlinksHither] = ipage;
  365. }
  366. }
  367. }
  368. }
  369. }
  370. my ground = true;
  371. }
  372. integer ManPages_uniqueLinksHither (ManPages me, integer ipage) {
  373. ManPage page = my pages.at [ipage];
  374. integer result = page -> nlinksHither;
  375. for (integer ilinkHither = 1; ilinkHither <= page -> nlinksHither; ilinkHither ++) {
  376. integer link = page -> linksHither [ilinkHither];
  377. for (integer ilinkThither = 1; ilinkThither <= page -> nlinksThither; ilinkThither ++)
  378. if (page -> linksThither [ilinkThither] == link) { result --; break; }
  379. }
  380. return result;
  381. }
  382. integer ManPages_lookUp (ManPages me, conststring32 title) {
  383. if (! my ground) grind (me);
  384. return lookUp_sorted (me, title);
  385. }
  386. static integer ManPages_lookUp_caseSensitive (ManPages me, conststring32 title) {
  387. if (! my ground) grind (me);
  388. for (integer i = 1; i <= my pages.size; i ++) {
  389. ManPage page = my pages.at [i];
  390. if (str32equ (page -> title.get(), title)) return i;
  391. }
  392. return 0;
  393. }
  394. conststring32vector ManPages_getTitles (ManPages me) {
  395. if (! my ground) grind (me);
  396. if (! my titles) {
  397. my titles = autostring32vector (my pages.size);
  398. for (integer i = 1; i <= my pages.size; i ++) {
  399. ManPage page = my pages.at [i];
  400. my titles [i] = Melder_dup (page -> title.get());
  401. }
  402. }
  403. return my titles.get();
  404. }
  405. static const struct stylesInfo {
  406. conststring32 htmlIn, htmlOut;
  407. } stylesInfo [] = {
  408. { nullptr, nullptr },
  409. /* INTRO: */ { U"<p>", U"</p>" },
  410. /* ENTRY: */ { U"<h3>", U"</h3>" },
  411. /* NORMAL: */ { U"<p>", U"</p>" },
  412. /* LIST_ITEM: */ { U"<dd>", U"" },
  413. /* TAG: */ { U"<dt>", U"" },
  414. /* DEFINITION: */ { U"<dd>", U"" },
  415. /* CODE: */ { U"<code>", U"<br></code>" },
  416. /* PROTOTYPE: */ { U"<p>", U"</p>" },
  417. /* FORMULA: */ { U"<table width=\"100%\"><tr><td align=middle>", U"</table>" },
  418. /* PICTURE: */ { U"<p>", U"</p>" },
  419. /* SCRIPT: */ { U"<p>", U"</p>" },
  420. /* LIST_ITEM1: */ { U"<dd>&nbsp;&nbsp;&nbsp;", U"" },
  421. /* LIST_ITEM2: */ { U"<dd>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;", U"" },
  422. /* LIST_ITEM3: */ { U"<dd>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;", U"" },
  423. /* TAG1: */ { U"<dt>&nbsp;&nbsp;&nbsp;", U"" },
  424. /* TAG2: */ { U"<dt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;", U"" },
  425. /* TAG3: */ { U"<dt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;", U"" },
  426. /* DEFINITION1: */ { U"<dd>&nbsp;&nbsp;&nbsp;", U"" },
  427. /* DEFINITION2: */ { U"<dd>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;", U"" },
  428. /* DEFINITION3: */ { U"<dd>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;", U"" },
  429. /* CODE1: */ { U"<code>&nbsp;&nbsp;&nbsp;", U"<br></code>" },
  430. /* CODE2: */ { U"<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;", U"<br></code>" },
  431. /* CODE3: */ { U"<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;", U"<br></code>" },
  432. /* CODE4: */ { U"<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;", U"<br></code>" },
  433. /* CODE5: */ { U"<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;", U"<br></code>" }
  434. };
  435. static void writeParagraphsAsHtml (ManPages me, MelderFile file, ManPage_Paragraph paragraphs, MelderString *buffer) {
  436. integer numberOfPictures = 0;
  437. bool inList = false, inItalic = false, inBold = false;
  438. bool inSub = false, inCode = false, inSuper = false, ul = false, inSmall = false;
  439. bool wordItalic = false, wordBold = false, wordCode = false, letterSuper = false;
  440. for (ManPage_Paragraph paragraph = paragraphs; (int) paragraph -> type != 0; paragraph ++) {
  441. const char32 *p = & paragraph -> text [0];
  442. bool inTable, inPromptedTable;
  443. bool isListItem = paragraph -> type == kManPage_type::LIST_ITEM ||
  444. (paragraph -> type >= kManPage_type::LIST_ITEM1 && paragraph -> type <= kManPage_type::LIST_ITEM3);
  445. bool isTag = paragraph -> type == kManPage_type::TAG ||
  446. (paragraph -> type >= kManPage_type::TAG1 && paragraph -> type <= kManPage_type::TAG3);
  447. bool isDefinition = paragraph -> type == kManPage_type::DEFINITION ||
  448. (paragraph -> type >= kManPage_type::DEFINITION1 && paragraph -> type <= kManPage_type::DEFINITION3);
  449. /*bool isCode = paragraph -> type == kManPage_type::CODE ||
  450. (paragraph -> type >= kManPage_type::CODE1 && paragraph -> type <= kManPage_type::CODE5);*/
  451. if (paragraph -> type == kManPage_type::PICTURE) {
  452. numberOfPictures ++;
  453. structMelderFile pngFile;
  454. MelderFile_copy (file, & pngFile);
  455. pngFile. path [str32len (pngFile. path) - 5] = U'\0'; // delete extension ".html"
  456. str32cat (pngFile. path, Melder_cat (U"_", numberOfPictures, U".png"));
  457. {// scope
  458. autoGraphics graphics = Graphics_create_pngfile (& pngFile, 300, 0.0, paragraph -> width, 0.0, paragraph -> height);
  459. Graphics_setFont (graphics.get(), kGraphics_font::TIMES);
  460. Graphics_setFontStyle (graphics.get(), 0);
  461. Graphics_setFontSize (graphics.get(), 12);
  462. Graphics_setWrapWidth (graphics.get(), 0);
  463. Graphics_setViewport (graphics.get(), 0.0, paragraph -> width, 0.0, paragraph -> height);
  464. paragraph -> draw (graphics.get());
  465. Graphics_setViewport (graphics.get(), 0, 1, 0, 1);
  466. Graphics_setWindow (graphics.get(), 0, 1, 0, 1);
  467. Graphics_setTextAlignment (graphics.get(), Graphics_LEFT, Graphics_BOTTOM);
  468. }
  469. MelderString_append (buffer, Melder_cat (U"<p align=middle><img height=", paragraph -> height * 100,
  470. U" width=", paragraph -> width * 100, U" src=", MelderFile_name (& pngFile), U"></p>"));
  471. continue;
  472. }
  473. if (paragraph -> type == kManPage_type::SCRIPT) {
  474. autoInterpreter interpreter = Interpreter_createFromEnvironment (nullptr);
  475. numberOfPictures ++;
  476. structMelderFile pdfFile;
  477. MelderFile_copy (file, & pdfFile);
  478. pdfFile. path [str32len (pdfFile. path) - 5] = U'\0'; // delete extension ".html"
  479. str32cat (pdfFile. path, Melder_cat (U"_", numberOfPictures, U".pdf"));
  480. {// scope
  481. autoGraphics graphics = Graphics_create_pdffile (& pdfFile, 100, 0.0, paragraph -> width, 0.0, paragraph -> height);
  482. Graphics_setFont (graphics.get(), kGraphics_font::TIMES);
  483. Graphics_setFontStyle (graphics.get(), 0);
  484. Graphics_setFontSize (graphics.get(), 12);
  485. Graphics_setWrapWidth (graphics.get(), 0);
  486. static structPraatApplication praatApplication;
  487. static structPraatObjects praatObjects;
  488. static structPraatPicture praatPicture;
  489. theCurrentPraatApplication = & praatApplication;
  490. theCurrentPraatApplication -> batch = true;
  491. theCurrentPraatApplication -> topShell = theForegroundPraatApplication. topShell; // needed for UiForm_create () in dialogs
  492. theCurrentPraatObjects = (PraatObjects) & praatObjects;
  493. theCurrentPraatPicture = (PraatPicture) & praatPicture;
  494. theCurrentPraatPicture -> graphics = graphics.get(); // FIXME: should be move()?
  495. theCurrentPraatPicture -> font = (int) kGraphics_font::TIMES;
  496. theCurrentPraatPicture -> fontSize = 12;
  497. theCurrentPraatPicture -> lineType = Graphics_DRAWN;
  498. theCurrentPraatPicture -> colour = Graphics_BLACK;
  499. theCurrentPraatPicture -> lineWidth = 1.0;
  500. theCurrentPraatPicture -> arrowSize = 1.0;
  501. theCurrentPraatPicture -> speckleSize = 1.0;
  502. theCurrentPraatPicture -> x1NDC = 0.0;
  503. theCurrentPraatPicture -> x2NDC = paragraph -> width;
  504. theCurrentPraatPicture -> y1NDC = 0.0;
  505. theCurrentPraatPicture -> y2NDC = paragraph -> height;
  506. Graphics_setViewport (graphics.get(), theCurrentPraatPicture -> x1NDC, theCurrentPraatPicture -> x2NDC, theCurrentPraatPicture -> y1NDC, theCurrentPraatPicture -> y2NDC);
  507. Graphics_setWindow (graphics.get(), 0.0, 1.0, 0.0, 1.0);
  508. integer x1DC, y1DC, x2DC, y2DC;
  509. Graphics_WCtoDC (graphics.get(), 0.0, 0.0, & x1DC, & y2DC);
  510. Graphics_WCtoDC (graphics.get(), 1.0, 1.0, & x2DC, & y1DC);
  511. Graphics_resetWsViewport (graphics.get(), x1DC, x2DC, y1DC, y2DC);
  512. Graphics_setWsWindow (graphics.get(), 0.0, paragraph -> width, 0.0, paragraph -> height);
  513. theCurrentPraatPicture -> x1NDC = 0.0;
  514. theCurrentPraatPicture -> x2NDC = paragraph -> width;
  515. theCurrentPraatPicture -> y1NDC = 0.0;
  516. theCurrentPraatPicture -> y2NDC = paragraph -> height;
  517. Graphics_setViewport (graphics.get(), theCurrentPraatPicture -> x1NDC, theCurrentPraatPicture -> x2NDC, theCurrentPraatPicture -> y1NDC, theCurrentPraatPicture -> y2NDC);
  518. {// scope
  519. autoMelderProgressOff progress;
  520. autoMelderWarningOff warning;
  521. autoMelderSaveDefaultDir saveDir;
  522. if (! MelderDir_isNull (& my rootDirectory)) {
  523. Melder_setDefaultDir (& my rootDirectory);
  524. }
  525. try {
  526. autostring32 text = Melder_dup (p);
  527. Interpreter_run (interpreter.get(), text.get());
  528. } catch (MelderError) {
  529. trace (U"interpreter fails on ", pdfFile. path);
  530. Melder_flushError ();
  531. }
  532. }
  533. Graphics_setViewport (graphics.get(), 0.0, 1.0, 0.0, 1.0);
  534. Graphics_setWindow (graphics.get(), 0.0, 1.0, 0.0, 1.0);
  535. Graphics_setTextAlignment (graphics.get(), Graphics_LEFT, Graphics_BOTTOM);
  536. }
  537. structMelderFile tiffFile;
  538. MelderFile_copy (file, & tiffFile);
  539. tiffFile. path [str32len (tiffFile. path) - 5] = U'\0'; // delete extension ".html"
  540. str32cat (tiffFile. path, Melder_cat (U"_", numberOfPictures, U".png"));
  541. system (Melder_peek32to8 (Melder_cat (U"/usr/local/bin/gs -q -dNOPAUSE "
  542. "-r200x200 -sDEVICE=png16m -sOutputFile=", tiffFile.path,
  543. U" ", pdfFile. path, U" quit.ps")));
  544. MelderFile_delete (& pdfFile);
  545. MelderString_append (buffer, U"<p align=middle><img height=", paragraph -> height * 100,
  546. U" width=", paragraph -> width * 100, U" src=", MelderFile_name (& tiffFile), U"></p>");
  547. theCurrentPraatApplication = & theForegroundPraatApplication;
  548. theCurrentPraatObjects = & theForegroundPraatObjects;
  549. theCurrentPraatPicture = & theForegroundPraatPicture;
  550. continue;
  551. }
  552. if (isListItem || isTag || isDefinition) {
  553. if (! inList) {
  554. ul = isListItem && (p [0] == U'•' || (p [0] == U'\\' && p [1] == U'b' && p [2] == U'u'));
  555. MelderString_append (buffer, ul ? U"<ul>\n" : U"<dl>\n");
  556. inList = true;
  557. }
  558. if (ul) {
  559. if (p [0] == U'•' && p [1] == U' ') p += 1;
  560. if (p [0] == U'\\' && p [1] == U'b' && p [2] == U'u' && p [3] == U' ') p += 3;
  561. }
  562. MelderString_append (buffer, ul ? U"<li>" : stylesInfo [(int) paragraph -> type]. htmlIn, U"\n");
  563. } else {
  564. if (inList) {
  565. MelderString_append (buffer, ul ? U"</ul>\n" : U"</dl>\n");
  566. inList = ul = false;
  567. }
  568. MelderString_append (buffer, stylesInfo [(int) paragraph -> type]. htmlIn, U"\n");
  569. }
  570. inTable = !! str32chr (p, U'\t');
  571. if (inTable) {
  572. if (*p == U'\t') {
  573. MelderString_append (buffer, U"<table border=0 cellpadding=0 cellspacing=0><tr><td width=100 align=middle>");
  574. p ++;
  575. inPromptedTable = false;
  576. } else {
  577. MelderString_append (buffer, U"<table border=0 cellpadding=0 cellspacing=0><tr><td width=100 align=left>");
  578. inPromptedTable = true;
  579. }
  580. }
  581. /*
  582. * Leading spaces should be visible (mainly used in code fragments).
  583. */
  584. while (*p == U' ') {
  585. MelderString_append (buffer, U"&nbsp;");
  586. p ++;
  587. }
  588. while (*p) {
  589. if (wordItalic && ! isSingleWordCharacter (*p)) { MelderString_append (buffer, U"</i>"); wordItalic = false; }
  590. if (wordBold && ! isSingleWordCharacter (*p)) { MelderString_append (buffer, U"</b>"); wordBold = false; }
  591. if (wordCode && ! isSingleWordCharacter (*p)) { MelderString_append (buffer, U"</code>"); wordCode = false; }
  592. if (*p == U'@') {
  593. static MelderString link, linkText;
  594. MelderString_empty (& link);
  595. MelderString_empty (& linkText);
  596. if (p [1] == U'@') {
  597. p += 2;
  598. while (*p != U'@' && *p != U'|' && *p != U'\0') MelderString_append (& link, *p++);
  599. if (*p == U'|') {
  600. p ++; // skip '|'
  601. while (*p != U'@' && *p != U'\0') {
  602. if (*p == U'^') {
  603. if (inSuper) {
  604. MelderString_append (& linkText, U"</sup>"); inSuper = false; p ++;
  605. } else if (p [1] == U'^') {
  606. MelderString_append (& linkText, U"<sup>"); inSuper = true; p += 2;
  607. } else {
  608. MelderString_append (& linkText, U"<sup>"); letterSuper = true; p ++;
  609. }
  610. } else {
  611. if (*p == U'\\') {
  612. char32 kar1 = *++p, kar2 = *++p;
  613. Longchar_Info info = Longchar_getInfo (kar1, kar2);
  614. if (info -> unicode < 127) {
  615. MelderString_appendCharacter (& linkText, info -> unicode ? info -> unicode : U'?');
  616. } else {
  617. MelderString_append (& linkText, U"&#", (int) info -> unicode, U";");
  618. }
  619. p ++;
  620. } else {
  621. if (*p < 127) {
  622. MelderString_appendCharacter (& linkText, *p);
  623. } else {
  624. MelderString_append (& linkText, U"&#", (int) *p, U";");
  625. }
  626. p ++;
  627. }
  628. if (letterSuper) {
  629. //if (wordItalic) { MelderString_append (buffer, U"</i>"); wordItalic = false; }
  630. //if (wordBold) { MelderString_append (buffer, U"</b>"); wordBold = false; }
  631. MelderString_append (& linkText, U"</sup>"); letterSuper = false;
  632. }
  633. }
  634. }
  635. } else {
  636. MelderString_copy (& linkText, link.string);
  637. }
  638. if (*p) p ++;
  639. } else {
  640. p ++;
  641. while (isSingleWordCharacter (*p) && *p != U'\0') MelderString_append (& link, *p++);
  642. MelderString_copy (& linkText, link.string);
  643. }
  644. /*
  645. * We write the link in the following format:
  646. * <a href="link.html">linkText</a>
  647. * If "link" (initial lower case) is not in the manual, we write "Link.html" instead.
  648. * All spaces and strange symbols in "link" are replaced by underscores,
  649. * because it will be a file name (see ManPages_writeAllToHtmlDir).
  650. * The file name will have no more than 30 or 60 characters, and no less than 1.
  651. */
  652. MelderString_append (buffer, U"<a href=\"");
  653. if (str32nequ (link.string, U"\\FI", 3)) {
  654. MelderString_append (buffer, link.string + 3); // file link
  655. } else {
  656. char32 *q = link.string;
  657. if (! ManPages_lookUp_caseSensitive (me, link.string)) {
  658. MelderString_appendCharacter (buffer, Melder_toUpperCase (link.string [0]));
  659. if (*q) q ++; // first letter already written
  660. }
  661. while (*q && q - link.string < LONGEST_FILE_NAME) {
  662. if (! isAllowedFileNameCharacter (*q)) MelderString_appendCharacter (buffer, U'_');
  663. else MelderString_appendCharacter (buffer, *q);
  664. q ++;
  665. }
  666. if (link.string [0] == U'\0') MelderString_appendCharacter (buffer, U'_'); /* Otherwise Mac problems or Unix invisibility. */
  667. MelderString_append (buffer, U".html");
  668. }
  669. MelderString_append (buffer, U"\">", linkText.string, U"</a>");
  670. } else if (*p == U'%') {
  671. if (inItalic) { MelderString_append (buffer, U"</i>"); inItalic = false; p ++; }
  672. else if (p [1] == U'%') { MelderString_append (buffer, U"<i>"); inItalic = true; p += 2; }
  673. else if (p [1] == U'#') { MelderString_append (buffer, U"<i><b>"); wordItalic = true; wordBold = true; p += 2; }
  674. else { MelderString_append (buffer, U"<i>"); wordItalic = true; p ++; }
  675. } else if (*p == U'_') {
  676. if (inSub) {
  677. /*if (wordItalic) { MelderString_append (buffer, U"</i>"); wordItalic = false; }
  678. if (wordBold) { MelderString_append (buffer, U"</b>"); wordBold = false; }*/
  679. MelderString_append (buffer, U"</sub>"); inSub = false; p ++;
  680. } else if (p [1] == U'_') {
  681. if (wordItalic) { MelderString_append (buffer, U"</i>"); wordItalic = false; }
  682. if (wordBold) { MelderString_append (buffer, U"</b>"); wordBold = false; }
  683. MelderString_append (buffer, U"<sub>"); inSub = true; p += 2;
  684. } else { MelderString_append (buffer, U"_"); p ++; }
  685. } else if (*p == U'#') {
  686. if (inBold) { MelderString_append (buffer, U"</b>"); inBold = false; p ++; }
  687. else if (p [1] == U'#') { MelderString_append (buffer, U"<b>"); inBold = true; p += 2; }
  688. else if (p [1] == U'%') { MelderString_append (buffer, U"<b><i>"); wordBold = true; wordItalic = true; p += 2; }
  689. else { MelderString_append (buffer, U"<b>"); wordBold = true; p ++; }
  690. } else if (*p == U'$') {
  691. if (inCode) { MelderString_append (buffer, U"</code>"); inCode = false; p ++; }
  692. else if (p [1] == U'$') { MelderString_append (buffer, U"<code>"); inCode = true; p += 2; }
  693. else { MelderString_append (buffer, U"<code>"); wordCode = true; p ++; }
  694. } else if (*p == U'^') {
  695. if (inSuper) {
  696. /*if (wordItalic) { MelderString_append (buffer, U"</i>"); wordItalic = false; }
  697. if (wordBold) { MelderString_append (buffer, U"</b>"); wordBold = false; }*/
  698. MelderString_append (buffer, U"</sup>"); inSuper = false; p ++;
  699. } else if (p [1] == U'^') {
  700. /*if (wordItalic) { MelderString_append (buffer, U"</i>"); wordItalic = false; }
  701. if (wordBold) { MelderString_append (buffer, U"</b>"); wordBold = false; }*/
  702. MelderString_append (buffer, U"<sup>"); inSuper = true; p += 2;
  703. } else {
  704. /*if (wordItalic) { MelderString_append (buffer, U"</i>"); wordItalic = false; }
  705. if (wordBold) { MelderString_append (buffer, U"</b>"); wordBold = false; }*/
  706. MelderString_append (buffer, U"<sup>"); letterSuper = true; p ++;
  707. }
  708. } else if (*p == U'}') {
  709. if (inSmall) { MelderString_append (buffer, U"</font>"); inSmall = false; p ++; }
  710. else { MelderString_append (buffer, U"}"); p ++; }
  711. } else if (*p == U'\\' && p [1] == U's' && p [2] == U'{') {
  712. MelderString_append (buffer, U"<font size=-1>"); inSmall = true; p += 3;
  713. } else if (*p == U'\t' && inTable) {
  714. if (inPromptedTable) {
  715. inPromptedTable = false;
  716. p ++; // skip one tab
  717. } else {
  718. MelderString_append (buffer, U"<td width=100 align=middle>"); p ++;
  719. }
  720. } else if (*p == U'<') {
  721. MelderString_append (buffer, U"&lt;"); p ++;
  722. } else if (*p == U'>') {
  723. MelderString_append (buffer, U"&gt;"); p ++;
  724. } else if (*p == U'&') {
  725. MelderString_append (buffer, U"&amp;"); p ++;
  726. } else {
  727. /*if (wordItalic && ! isSingleWordCharacter (*p)) { MelderString_append (buffer, U"</i>"); wordItalic = false; }
  728. if (wordBold && ! isSingleWordCharacter (*p)) { MelderString_append (buffer, U"</b>"); wordBold = false; }
  729. if (wordCode && ! isSingleWordCharacter (*p)) { MelderString_append (buffer, U"</code>"); wordCode = false; }*/
  730. if (*p == U'\\') {
  731. char32 kar1 = *++p, kar2 = *++p;
  732. Longchar_Info info = Longchar_getInfo (kar1, kar2);
  733. if (info -> unicode < 127) {
  734. MelderString_appendCharacter (buffer, info -> unicode ? info -> unicode : U'?');
  735. } else {
  736. MelderString_append (buffer, U"&#", (int) info -> unicode, U";");
  737. }
  738. p ++;
  739. } else {
  740. if (*p < 127) {
  741. MelderString_appendCharacter (buffer, *p);
  742. } else {
  743. MelderString_append (buffer, U"&#", (int) *p, U";");
  744. }
  745. p ++;
  746. }
  747. if (letterSuper) {
  748. if (wordItalic) { MelderString_append (buffer, U"</i>"); wordItalic = false; }
  749. if (wordBold) { MelderString_append (buffer, U"</b>"); wordBold = false; }
  750. MelderString_append (buffer, U"</sup>"); letterSuper = false;
  751. }
  752. }
  753. }
  754. if (inItalic || wordItalic) { MelderString_append (buffer, U"</i>"); inItalic = wordItalic = false; }
  755. if (inBold || wordBold) { MelderString_append (buffer, U"</b>"); inBold = wordBold = false; }
  756. if (inCode || wordCode) { MelderString_append (buffer, U"</code>"); inCode = wordCode = false; }
  757. if (inSub) { MelderString_append (buffer, U"</sub>"); inSub = false; }
  758. if (inSuper || letterSuper) { MelderString_append (buffer, U"</sup>"); inSuper = letterSuper = false; }
  759. if (inTable) { MelderString_append (buffer, U"</table>"); inTable = false; }
  760. MelderString_append (buffer, stylesInfo [(int) paragraph -> type]. htmlOut, U"\n");
  761. }
  762. if (inList) { MelderString_append (buffer, ul ? U"</ul>\n" : U"</dl>\n"); inList = false; }
  763. }
  764. static const conststring32 month [] =
  765. { U"", U"January", U"February", U"March", U"April", U"May", U"June",
  766. U"July", U"August", U"September", U"October", U"November", U"December" };
  767. static void writePageAsHtml (ManPages me, MelderFile file, integer ipage, MelderString *buffer) {
  768. ManPage page = my pages.at [ipage];
  769. ManPage_Paragraph paragraphs = page -> paragraphs;
  770. MelderString_append (buffer, U"<html><head><meta name=\"robots\" content=\"index,follow\">"
  771. U"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n"
  772. U"<title>", page -> title.get(), U"</title></head><body bgcolor=\"#FFFFFF\">\n\n");
  773. MelderString_append (buffer, U"<table border=0 cellpadding=0 cellspacing=0><tr><td bgcolor=\"#CCCC00\">"
  774. U"<table border=4 cellpadding=9><tr><td align=middle bgcolor=\"#000000\">"
  775. U"<font face=\"Palatino,Times\" size=6 color=\"#999900\"><b>\n",
  776. page -> title.get(), U"\n</b></font></table></table>\n");
  777. writeParagraphsAsHtml (me, file, paragraphs, buffer);
  778. if (ManPages_uniqueLinksHither (me, ipage)) {
  779. integer ilink, jlink, lastParagraph = 0;
  780. while ((int) page -> paragraphs [lastParagraph]. type != 0) lastParagraph ++;
  781. if (lastParagraph > 0) {
  782. conststring32 text = page -> paragraphs [lastParagraph - 1]. text;
  783. if (text && text [0] != U'\0' && text [str32len (text) - 1] != U':')
  784. MelderString_append (buffer, U"<h3>Links to this page</h3>\n");
  785. }
  786. MelderString_append (buffer, U"<ul>\n");
  787. for (ilink = 1; ilink <= page -> nlinksHither; ilink ++) {
  788. integer link = page -> linksHither [ilink];
  789. bool alreadyShown = false;
  790. for (jlink = 1; jlink <= page -> nlinksThither; jlink ++)
  791. if (page -> linksThither [jlink] == link)
  792. alreadyShown = true;
  793. if (! alreadyShown) {
  794. ManPage linkingPage = my pages.at [page -> linksHither [ilink]];
  795. conststring32 title = linkingPage -> title.get();
  796. const char32 *p;
  797. MelderString_append (buffer, U"<li><a href=\"");
  798. for (p = & title [0]; *p; p ++) {
  799. if (p - title >= LONGEST_FILE_NAME) break;
  800. if (! isAllowedFileNameCharacter (*p)) MelderString_append (buffer, U"_");
  801. else MelderString_appendCharacter (buffer, *p);
  802. }
  803. if (title [0] == U'\0') MelderString_append (buffer, U"_");
  804. MelderString_append (buffer, U".html\">", title, U"</a>\n");
  805. }
  806. }
  807. MelderString_append (buffer, U"</ul>\n");
  808. }
  809. MelderString_append (buffer, U"<hr>\n<address>\n\t<p>&copy; ", page -> author.get());
  810. if (page -> date) {
  811. integer date = page -> date;
  812. int imonth = date % 10000 / 100;
  813. if (imonth < 0 || imonth > 12) imonth = 0;
  814. MelderString_append (buffer, U", ", month [imonth], U" ", date % 100);
  815. MelderString_append (buffer, U", ", date / 10000);
  816. }
  817. MelderString_append (buffer, U"</p>\n</address>\n</body>\n</html>\n");
  818. }
  819. void ManPages_writeOneToHtmlFile (ManPages me, integer ipage, MelderFile file) {
  820. static MelderString buffer { };
  821. MelderString_empty (& buffer);
  822. writePageAsHtml (me, file, ipage, & buffer);
  823. MelderFile_writeText (file, buffer.string, kMelder_textOutputEncoding::UTF8);
  824. }
  825. void ManPages_writeAllToHtmlDir (ManPages me, conststring32 dirPath) {
  826. structMelderDir dir { };
  827. Melder_pathToDir (dirPath, & dir);
  828. for (integer ipage = 1; ipage <= my pages.size; ipage ++) {
  829. ManPage page = my pages.at [ipage];
  830. char32 fileName [256];
  831. Melder_assert (str32len (page -> title.get()) < 256 - 100);
  832. trace (U"page ", ipage, U": ", page -> title.get());
  833. Melder_sprint (fileName,256, page -> title.get());
  834. for (char32 *p = fileName; *p; p ++)
  835. if (! isAllowedFileNameCharacter (*p))
  836. *p = U'_';
  837. if (fileName [0] == U'\0')
  838. str32cpy (fileName, U"_"); // no empty file names please
  839. fileName [LONGEST_FILE_NAME] = U'\0';
  840. str32cat (fileName, U".html");
  841. static MelderString buffer { };
  842. MelderString_empty (& buffer);
  843. structMelderFile file { };
  844. MelderDir_getFile (& dir, fileName, & file);
  845. writePageAsHtml (me, & file, ipage, & buffer);
  846. /*
  847. * An optimization because reading is much faster than writing:
  848. * we write the file only if the old file is different or doesn't exist.
  849. */
  850. autostring32 oldText;
  851. try {
  852. oldText = MelderFile_readText (& file);
  853. } catch (MelderError) {
  854. Melder_clearError ();
  855. }
  856. if (! oldText // doesn't the file exist yet?
  857. || str32cmp (buffer.string, oldText.get())) // isn't the old file identical to the new text?
  858. {
  859. MelderFile_writeText (& file, buffer.string, kMelder_textOutputEncoding::UTF8); // then write the new text
  860. }
  861. }
  862. }
  863. /* End of file ManPages.cpp */