tohtml.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812
  1. #include <u.h>
  2. #include <libc.h>
  3. #include <bio.h>
  4. #include <String.h>
  5. #include <thread.h>
  6. #include "wiki.h"
  7. /*
  8. * Get HTML and text templates from underlying file system.
  9. * Caches them, which means changes don't take effect for
  10. * up to Tcache seconds after they are made.
  11. *
  12. * If the files are deleted, we keep returning the last
  13. * known copy.
  14. */
  15. enum {
  16. WAIT = 60
  17. };
  18. static char *name[2*Ntemplate] = {
  19. [Tpage] "page.html",
  20. [Tedit] "edit.html",
  21. [Tdiff] "diff.html",
  22. [Thistory] "history.html",
  23. [Tnew] "new.html",
  24. [Toldpage] "oldpage.html",
  25. [Twerror] "werror.html",
  26. [Ntemplate+Tpage] "page.txt",
  27. [Ntemplate+Tdiff] "diff.txt",
  28. [Ntemplate+Thistory] "history.txt",
  29. [Ntemplate+Toldpage] "oldpage.txt",
  30. [Ntemplate+Twerror] "werror.txt",
  31. };
  32. static struct {
  33. RWLock;
  34. String *s;
  35. ulong t;
  36. Qid qid;
  37. } cache[2*Ntemplate];
  38. static void
  39. cacheinit(void)
  40. {
  41. int i;
  42. static int x;
  43. static Lock l;
  44. if(x)
  45. return;
  46. lock(&l);
  47. if(x){
  48. unlock(&l);
  49. return;
  50. }
  51. for(i=0; i<2*Ntemplate; i++)
  52. if(name[i])
  53. cache[i].s = s_copy("");
  54. x = 1;
  55. unlock(&l);
  56. }
  57. static String*
  58. gettemplate(int type)
  59. {
  60. int n;
  61. Biobuf *b;
  62. Dir *d;
  63. String *s, *ns;
  64. if(name[type]==nil)
  65. return nil;
  66. cacheinit();
  67. rlock(&cache[type]);
  68. if(0 && cache[type].t+Tcache >= time(0)){
  69. s = s_incref(cache[type].s);
  70. runlock(&cache[type]);
  71. return s;
  72. }
  73. runlock(&cache[type]);
  74. // d = nil;
  75. wlock(&cache[type]);
  76. if(0 && cache[type].t+Tcache >= time(0) || (d = wdirstat(name[type])) == nil)
  77. goto Return;
  78. if(0 && d->qid.vers == cache[type].qid.vers && d->qid.path == cache[type].qid.path){
  79. cache[type].t = time(0);
  80. goto Return;
  81. }
  82. if((b = wBopen(name[type], OREAD)) == nil)
  83. goto Return;
  84. ns = s_reset(nil);
  85. do
  86. n = s_read(b, ns, Bsize);
  87. while(n > 0);
  88. Bterm(b);
  89. if(n < 0)
  90. goto Return;
  91. s_free(cache[type].s);
  92. cache[type].s = ns;
  93. cache[type].qid = d->qid;
  94. cache[type].t = time(0);
  95. Return:
  96. free(d);
  97. s = s_incref(cache[type].s);
  98. wunlock(&cache[type]);
  99. return s;
  100. }
  101. /*
  102. * Write wiki document in HTML.
  103. */
  104. static String*
  105. s_escappend(String *s, char *p, int pre)
  106. {
  107. char *q;
  108. while(q = strpbrk(p, pre ? "<>&" : " <>&")){
  109. s = s_nappend(s, p, q-p);
  110. switch(*q){
  111. case '<':
  112. s = s_append(s, "&lt;");
  113. break;
  114. case '>':
  115. s = s_append(s, "&gt;");
  116. break;
  117. case '&':
  118. s = s_append(s, "&amp;");
  119. break;
  120. case ' ':
  121. s = s_append(s, "\n");
  122. }
  123. p = q+1;
  124. }
  125. s = s_append(s, p);
  126. return s;
  127. }
  128. static char*
  129. mkurl(char *s, int ty)
  130. {
  131. char *p, *q;
  132. if(strncmp(s, "http:", 5)==0
  133. || strncmp(s, "https:", 6)==0
  134. || strncmp(s, "#", 1)==0
  135. || strncmp(s, "ftp:", 4)==0
  136. || strncmp(s, "mailto:", 7)==0
  137. || strncmp(s, "telnet:", 7)==0
  138. || strncmp(s, "file:", 5)==0)
  139. return estrdup(s);
  140. if(strchr(s, ' ')==nil && strchr(s, '@')!=nil){
  141. p = emalloc(strlen(s)+8);
  142. strcpy(p, "mailto:");
  143. strcat(p, s);
  144. return p;
  145. }
  146. if(ty == Toldpage)
  147. p = smprint("../../%s", s);
  148. else
  149. p = smprint("../%s", s);
  150. for(q=p; *q; q++)
  151. if(*q==' ')
  152. *q = '_';
  153. return p;
  154. }
  155. String*
  156. pagehtml(String *s, Wpage *wtxt, int ty)
  157. {
  158. int inlist, inpre, inpara;
  159. char *p, tmp[40];
  160. Wpage *w;
  161. inlist = 0;
  162. inpre = 0;
  163. inpara = 0;
  164. for(w=wtxt; w; w=w->next){
  165. switch(w->type){
  166. case Wheading:
  167. /*
  168. if(!inpara){
  169. inpara = 1;
  170. s = s_append(s, "\n<p>\n");
  171. }
  172. */
  173. s = s_appendlist(s, "<br />\n<a name=\"",w->text,"\" /><h3>", w->text, "</h3>\n", nil);
  174. break;
  175. case Wpara:
  176. if(inlist){
  177. inlist = 0;
  178. s = s_append(s, "\n</ul>\n");
  179. }
  180. if(inpre){
  181. inpre = 0;
  182. s = s_append(s, "</pre>\n");
  183. }
  184. if(!inpara){
  185. inpara = 1;
  186. s = s_append(s, "\n<p>\n");
  187. }
  188. break;
  189. case Wbullet:
  190. if(inpre){
  191. inpre = 0;
  192. s = s_append(s, "</pre>\n");
  193. }
  194. if(!inlist){
  195. inlist = 1;
  196. s = s_append(s, "\n<ul>\n");
  197. }
  198. if(inpara)
  199. inpara = 0;
  200. s = s_append(s, "\n<li>\n");
  201. break;
  202. case Wlink:
  203. if(inpara)
  204. inpara = 0;
  205. if(w->url == nil)
  206. p = mkurl(w->text, ty);
  207. else
  208. p = w->url;
  209. s = s_appendlist(s, "<a href=\"", p, "\">", nil);
  210. s = s_escappend(s, w->text, 0);
  211. s = s_append(s, "</a>");
  212. if(w->url == nil)
  213. free(p);
  214. break;
  215. case Wman:
  216. if(inpara)
  217. inpara = 0;
  218. sprint(tmp, "%d", w->section);
  219. s = s_appendlist(s,
  220. "<a href=\"http://plan9.bell-labs.com/magic/man2html/",
  221. tmp, "/", w->text, "\"><i>", w->text, "</i>(",
  222. tmp, ")</a>", nil);
  223. break;
  224. case Wpre:
  225. if(inpara)
  226. inpara = 0;
  227. if(inlist){
  228. inlist = 0;
  229. s = s_append(s, "\n</ul>\n");
  230. }
  231. if(!inpre){
  232. inpre = 1;
  233. s = s_append(s, "\n<pre>\n");
  234. }
  235. s = s_escappend(s, w->text, 1);
  236. s = s_append(s, "\n");
  237. break;
  238. case Whr:
  239. s = s_append(s, "<hr />");
  240. break;
  241. case Wplain:
  242. if(inpre){
  243. inpre = 0;
  244. s = s_append(s, "</pre>\n");
  245. }
  246. if(inpara)
  247. inpara = 0;
  248. s = s_escappend(s, w->text, 0);
  249. break;
  250. }
  251. }
  252. if(inlist)
  253. s = s_append(s, "\n</ul>\n");
  254. if(inpre)
  255. s = s_append(s, "</pre>\n");
  256. if(!inpara)
  257. s = s_append(s, "\n<p>\n");
  258. return s;
  259. }
  260. static String*
  261. grey(String *s)
  262. {
  263. return s_append(s, "<font color=#777777>");
  264. }
  265. static String*
  266. ungrey(String *s)
  267. {
  268. return s_append(s, "</font>");
  269. }
  270. static String*
  271. copythru(String *s, char **newp, int *nlinep, int l)
  272. {
  273. char *oq, *q, *r;
  274. int ol;
  275. q = *newp;
  276. oq = q;
  277. ol = *nlinep;
  278. while(ol < l){
  279. if(r = strchr(q, '\n'))
  280. q = r+1;
  281. else{
  282. q += strlen(q);
  283. break;
  284. }
  285. ol++;
  286. }
  287. if(*nlinep < l)
  288. *nlinep = l;
  289. *newp = q;
  290. return s_nappend(s, oq, q-oq);
  291. }
  292. static int
  293. dodiff(char *f1, char *f2)
  294. {
  295. int p[2];
  296. if(pipe(p) < 0){
  297. return -1;
  298. }
  299. switch(fork()){
  300. case -1:
  301. return -1;
  302. case 0:
  303. close(p[0]);
  304. dup(p[1], 1);
  305. execl("/bin/diff", "diff", f1, f2, nil);
  306. _exits(nil);
  307. }
  308. close(p[1]);
  309. return p[0];
  310. }
  311. /* print document i grayed out, with only diffs relative to j in black */
  312. static String*
  313. s_diff(String *s, Whist *h, int i, int j)
  314. {
  315. char *p, *q, *pnew;
  316. int fdiff, fd1, fd2, n1, n2;
  317. Biobuf b;
  318. char fn1[40], fn2[40];
  319. String *new, *old;
  320. int nline;
  321. if(j < 0)
  322. return pagehtml(s, h->doc[i].wtxt, Tpage);
  323. strcpy(fn1, "/tmp/wiki.XXXXXX");
  324. strcpy(fn2, "/tmp/wiki.XXXXXX");
  325. if((fd1 = opentemp(fn1)) < 0 || (fd2 = opentemp(fn2)) < 0){
  326. close(fd1);
  327. s = s_append(s, "\nopentemp failed; sorry\n");
  328. return s;
  329. }
  330. new = pagehtml(s_reset(nil), h->doc[i].wtxt, Tpage);
  331. old = pagehtml(s_reset(nil), h->doc[j].wtxt, Tpage);
  332. write(fd1, s_to_c(new), s_len(new));
  333. write(fd2, s_to_c(old), s_len(old));
  334. fdiff = dodiff(fn2, fn1);
  335. if(fdiff < 0)
  336. s = s_append(s, "\ndiff failed; sorry\n");
  337. else{
  338. nline = 0;
  339. pnew = s_to_c(new);
  340. Binit(&b, fdiff, OREAD);
  341. while(p = Brdline(&b, '\n')){
  342. if(p[0]=='<' || p[0]=='>' || p[0]=='-')
  343. continue;
  344. p[Blinelen(&b)-1] = '\0';
  345. if((q = strpbrk(p, "acd")) == nil)
  346. continue;
  347. switch(*q){
  348. case 'a':
  349. case 'c':
  350. n1 = atoi(q+1);
  351. if(q = strchr(q, ','))
  352. n2 = atoi(q+1);
  353. else
  354. n2 = n1;
  355. s = grey(s);
  356. s = copythru(s, &pnew, &nline, n1-1);
  357. s = ungrey(s);
  358. s = copythru(s, &pnew, &nline, n2);
  359. break;
  360. }
  361. }
  362. close(fdiff);
  363. s = grey(s);
  364. s = s_append(s, pnew);
  365. s = ungrey(s);
  366. }
  367. s_free(new);
  368. s_free(old);
  369. close(fd1);
  370. close(fd2);
  371. return s;
  372. }
  373. static String*
  374. diffhtml(String *s, Whist *h)
  375. {
  376. int i;
  377. char tmp[50];
  378. char *atime;
  379. for(i=h->ndoc-1; i>=0; i--){
  380. s = s_append(s, "<hr>\n");
  381. if(i==h->current)
  382. sprint(tmp, "index.html");
  383. else
  384. sprint(tmp, "%lud", h->doc[i].time);
  385. atime = ctime(h->doc[i].time);
  386. atime[strlen(atime)-1] = '\0';
  387. s = s_appendlist(s,
  388. "<a href=\"", tmp, "\">",
  389. atime, "</a>", nil);
  390. if(h->doc[i].author)
  391. s = s_appendlist(s, ", ", h->doc[i].author, nil);
  392. if(h->doc[i].conflict)
  393. s = s_append(s, ", conflicting write");
  394. s = s_append(s, "\n");
  395. if(h->doc[i].comment)
  396. s = s_appendlist(s, "<br><i>", h->doc[i].comment, "</i>\n", nil);
  397. s = s_append(s, "<br><hr>");
  398. s = s_diff(s, h, i, i-1);
  399. }
  400. s = s_append(s, "<hr>");
  401. return s;
  402. }
  403. static String*
  404. historyhtml(String *s, Whist *h)
  405. {
  406. int i;
  407. char tmp[40];
  408. char *atime;
  409. s = s_append(s, "<ul>\n");
  410. for(i=h->ndoc-1; i>=0; i--){
  411. if(i==h->current)
  412. sprint(tmp, "index.html");
  413. else
  414. sprint(tmp, "%lud", h->doc[i].time);
  415. atime = ctime(h->doc[i].time);
  416. atime[strlen(atime)-1] = '\0';
  417. s = s_appendlist(s,
  418. "<li><a href=\"", tmp, "\">",
  419. atime, "</a>", nil);
  420. if(h->doc[i].author)
  421. s = s_appendlist(s, ", ", h->doc[i].author, nil);
  422. if(h->doc[i].conflict)
  423. s = s_append(s, ", conflicting write");
  424. s = s_append(s, "\n");
  425. if(h->doc[i].comment)
  426. s = s_appendlist(s, "<br><i>", h->doc[i].comment, "</i>\n", nil);
  427. }
  428. s = s_append(s, "</ul>");
  429. return s;
  430. }
  431. String*
  432. tohtml(Whist *h, Wdoc *d, int ty)
  433. {
  434. char *atime;
  435. char *p, *q, ver[40];
  436. int nsub;
  437. Sub sub[3];
  438. String *s, *t;
  439. t = gettemplate(ty);
  440. if(p = strstr(s_to_c(t), "PAGE"))
  441. q = p+4;
  442. else{
  443. p = s_to_c(t)+s_len(t);
  444. q = nil;
  445. }
  446. nsub = 0;
  447. if(h){
  448. sub[nsub] = (Sub){ "TITLE", h->title };
  449. nsub++;
  450. }
  451. if(d){
  452. sprint(ver, "%lud", d->time);
  453. sub[nsub] = (Sub){ "VERSION", ver };
  454. nsub++;
  455. atime = ctime(d->time);
  456. atime[strlen(atime)-1] = '\0';
  457. sub[nsub] = (Sub){ "DATE", atime };
  458. nsub++;
  459. }
  460. s = s_reset(nil);
  461. s = s_appendsub(s, s_to_c(t), p-s_to_c(t), sub, nsub);
  462. switch(ty){
  463. case Tpage:
  464. case Toldpage:
  465. s = pagehtml(s, d->wtxt, ty);
  466. break;
  467. case Tedit:
  468. s = pagetext(s, d->wtxt, 0);
  469. break;
  470. case Tdiff:
  471. s = diffhtml(s, h);
  472. break;
  473. case Thistory:
  474. s = historyhtml(s, h);
  475. break;
  476. case Tnew:
  477. case Twerror:
  478. break;
  479. }
  480. if(q)
  481. s = s_appendsub(s, q, strlen(q), sub, nsub);
  482. s_free(t);
  483. return s;
  484. }
  485. enum {
  486. LINELEN = 70,
  487. };
  488. static String*
  489. s_appendbrk(String *s, char *p, char *prefix, int dosharp)
  490. {
  491. char *e, *w, *x;
  492. int first, l;
  493. Rune r;
  494. first = 1;
  495. while(*p){
  496. s = s_append(s, p);
  497. e = strrchr(s_to_c(s), '\n');
  498. if(e == nil)
  499. e = s_to_c(s);
  500. else
  501. e++;
  502. if(utflen(e) <= LINELEN)
  503. break;
  504. x = e; l=LINELEN;
  505. while(l--)
  506. x+=chartorune(&r,x);
  507. x = strchr(x, ' ');
  508. if(x){
  509. *x = '\0';
  510. w = strrchr(e, ' ');
  511. *x = ' ';
  512. }else
  513. w = strrchr(e, ' ');
  514. if(w-s_to_c(s) < strlen(prefix))
  515. break;
  516. x = estrdup(w+1);
  517. *w = '\0';
  518. s->ptr = w;
  519. s_append(s, "\n");
  520. if(dosharp)
  521. s_append(s, "#");
  522. s_append(s, prefix);
  523. if(!first)
  524. free(p);
  525. first = 0;
  526. p = x;
  527. }
  528. if(!first)
  529. free(p);
  530. return s;
  531. }
  532. static void
  533. s_endline(String *s, int dosharp)
  534. {
  535. if(dosharp){
  536. if(s->ptr == s->base+1 && s->ptr[-1] == '#')
  537. return;
  538. if(s->ptr > s->base+1 && s->ptr[-1] == '#' && s->ptr[-2] == '\n')
  539. return;
  540. s_append(s, "\n#");
  541. }else{
  542. if(s->ptr > s->base+1 && s->ptr[-1] == '\n')
  543. return;
  544. s_append(s, "\n");
  545. }
  546. }
  547. String*
  548. pagetext(String *s, Wpage *page, int dosharp)
  549. {
  550. int inlist, inpara;
  551. char *prefix, *sharp, tmp[40];
  552. String *t;
  553. Wpage *w;
  554. inlist = 0;
  555. inpara = 0;
  556. prefix = "";
  557. sharp = dosharp ? "#" : "";
  558. s = s_append(s, sharp);
  559. for(w=page; w; w=w->next){
  560. switch(w->type){
  561. case Wheading:
  562. if(inlist){
  563. prefix = "";
  564. inlist = 0;
  565. }
  566. s_endline(s, dosharp);
  567. if(!inpara){
  568. inpara = 1;
  569. s = s_appendlist(s, "\n", sharp, nil);
  570. }
  571. s = s_appendlist(s, w->text, "\n", sharp, "\n", sharp, nil);
  572. break;
  573. case Wpara:
  574. s_endline(s, dosharp);
  575. if(inlist){
  576. prefix = "";
  577. inlist = 0;
  578. }
  579. if(!inpara){
  580. inpara = 1;
  581. s = s_appendlist(s, "\n", sharp, nil);
  582. }
  583. break;
  584. case Wbullet:
  585. s_endline(s, dosharp);
  586. if(!inlist)
  587. inlist = 1;
  588. if(inpara)
  589. inpara = 0;
  590. s = s_append(s, " *\t");
  591. prefix = "\t";
  592. break;
  593. case Wlink:
  594. if(inpara)
  595. inpara = 0;
  596. t = s_append(s_copy("["), w->text);
  597. if(w->url == nil)
  598. t = s_append(t, "]");
  599. else{
  600. t = s_append(t, " | ");
  601. t = s_append(t, w->url);
  602. t = s_append(t, "]");
  603. }
  604. s = s_appendbrk(s, s_to_c(t), prefix, dosharp);
  605. s_free(t);
  606. break;
  607. case Wman:
  608. if(inpara)
  609. inpara = 0;
  610. s = s_appendbrk(s, w->text, prefix, dosharp);
  611. sprint(tmp, "(%d)", w->section);
  612. s = s_appendbrk(s, tmp, prefix, dosharp);
  613. break;
  614. case Wpre:
  615. if(inlist){
  616. prefix = "";
  617. inlist = 0;
  618. }
  619. if(inpara)
  620. inpara = 0;
  621. s_endline(s, dosharp);
  622. s = s_appendlist(s, "! ", w->text, "\n", sharp, nil);
  623. break;
  624. case Whr:
  625. s_endline(s, dosharp);
  626. s = s_appendlist(s, "------------------------------------------------------ \n", sharp, nil);
  627. break;
  628. case Wplain:
  629. if(inpara)
  630. inpara = 0;
  631. s = s_appendbrk(s, w->text, prefix, dosharp);
  632. break;
  633. }
  634. }
  635. s_endline(s, dosharp);
  636. s->ptr--;
  637. *s->ptr = '\0';
  638. return s;
  639. }
  640. static String*
  641. historytext(String *s, Whist *h)
  642. {
  643. int i;
  644. char tmp[40];
  645. char *atime;
  646. for(i=h->ndoc-1; i>=0; i--){
  647. if(i==h->current)
  648. sprint(tmp, "[current]");
  649. else
  650. sprint(tmp, "[%lud/]", h->doc[i].time);
  651. atime = ctime(h->doc[i].time);
  652. atime[strlen(atime)-1] = '\0';
  653. s = s_appendlist(s, " * ", tmp, " ", atime, nil);
  654. if(h->doc[i].author)
  655. s = s_appendlist(s, ", ", h->doc[i].author, nil);
  656. if(h->doc[i].conflict)
  657. s = s_append(s, ", conflicting write");
  658. s = s_append(s, "\n");
  659. if(h->doc[i].comment)
  660. s = s_appendlist(s, "<i>", h->doc[i].comment, "</i>\n", nil);
  661. }
  662. return s;
  663. }
  664. String*
  665. totext(Whist *h, Wdoc *d, int ty)
  666. {
  667. char *atime;
  668. char *p, *q, ver[40];
  669. int nsub;
  670. Sub sub[3];
  671. String *s, *t;
  672. t = gettemplate(Ntemplate+ty);
  673. if(p = strstr(s_to_c(t), "PAGE"))
  674. q = p+4;
  675. else{
  676. p = s_to_c(t)+s_len(t);
  677. q = nil;
  678. }
  679. nsub = 0;
  680. if(h){
  681. sub[nsub] = (Sub){ "TITLE", h->title };
  682. nsub++;
  683. }
  684. if(d){
  685. sprint(ver, "%lud", d->time);
  686. sub[nsub] = (Sub){ "VERSION", ver };
  687. nsub++;
  688. atime = ctime(d->time);
  689. atime[strlen(atime)-1] = '\0';
  690. sub[nsub] = (Sub){ "DATE", atime };
  691. nsub++;
  692. }
  693. s = s_reset(nil);
  694. s = s_appendsub(s, s_to_c(t), p-s_to_c(t), sub, nsub);
  695. switch(ty){
  696. case Tpage:
  697. case Toldpage:
  698. s = pagetext(s, d->wtxt, 0);
  699. break;
  700. case Thistory:
  701. s = historytext(s, h);
  702. break;
  703. case Tnew:
  704. case Twerror:
  705. break;
  706. }
  707. if(q)
  708. s = s_appendsub(s, q, strlen(q), sub, nsub);
  709. s_free(t);
  710. return s;
  711. }
  712. String*
  713. doctext(String *s, Wdoc *d)
  714. {
  715. char tmp[40];
  716. sprint(tmp, "D%lud", d->time);
  717. s = s_append(s, tmp);
  718. if(d->comment){
  719. s = s_append(s, "\nC");
  720. s = s_append(s, d->comment);
  721. }
  722. if(d->author){
  723. s = s_append(s, "\nA");
  724. s = s_append(s, d->author);
  725. }
  726. if(d->conflict)
  727. s = s_append(s, "\nX");
  728. s = s_append(s, "\n");
  729. s = pagetext(s, d->wtxt, 1);
  730. return s;
  731. }