Annotation of src/usr.bin/mandoc/man_term.c, Revision 1.114
1.114 ! schwarze 1: /* $OpenBSD: man_term.c,v 1.113 2014/12/23 01:57:11 schwarze Exp $ */
1.1 kristaps 2: /*
1.84 schwarze 3: * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
1.94 schwarze 4: * Copyright (c) 2010-2014 Ingo Schwarze <schwarze@openbsd.org>
1.1 kristaps 5: *
6: * Permission to use, copy, modify, and distribute this software for any
1.2 schwarze 7: * purpose with or without fee is hereby granted, provided that the above
8: * copyright notice and this permission notice appear in all copies.
1.1 kristaps 9: *
1.2 schwarze 10: * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11: * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12: * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13: * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14: * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15: * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16: * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1.1 kristaps 17: */
1.13 schwarze 18: #include <sys/types.h>
19:
1.1 kristaps 20: #include <assert.h>
1.11 schwarze 21: #include <ctype.h>
1.1 kristaps 22: #include <stdio.h>
23: #include <stdlib.h>
24: #include <string.h>
25:
1.37 schwarze 26: #include "mandoc.h"
1.101 schwarze 27: #include "mandoc_aux.h"
1.18 schwarze 28: #include "out.h"
29: #include "man.h"
1.1 kristaps 30: #include "term.h"
1.18 schwarze 31: #include "main.h"
1.10 schwarze 32:
1.70 schwarze 33: #define MAXMARGINS 64 /* maximum number of indented scopes */
1.1 kristaps 34:
1.11 schwarze 35: struct mtermp {
36: int fl;
37: #define MANT_LITERAL (1 << 0)
1.70 schwarze 38: size_t lmargin[MAXMARGINS]; /* margins (incl. visible page) */
39: int lmargincur; /* index of current margin */
40: int lmarginsz; /* actual number of nested margins */
41: size_t offset; /* default offset to visible page */
1.88 schwarze 42: int pardist; /* vert. space before par., unit: [v] */
1.11 schwarze 43: };
44:
1.100 schwarze 45: #define DECL_ARGS struct termp *p, \
1.11 schwarze 46: struct mtermp *mt, \
1.1 kristaps 47: const struct man_node *n, \
1.89 schwarze 48: const struct man_meta *meta
1.1 kristaps 49:
50: struct termact {
51: int (*pre)(DECL_ARGS);
52: void (*post)(DECL_ARGS);
1.26 schwarze 53: int flags;
54: #define MAN_NOTEXT (1 << 0) /* Never has text children. */
1.1 kristaps 55: };
56:
1.42 schwarze 57: static int a2width(const struct termp *, const char *);
58: static size_t a2height(const struct termp *, const char *);
1.18 schwarze 59:
1.21 schwarze 60: static void print_man_nodelist(DECL_ARGS);
1.19 schwarze 61: static void print_man_node(DECL_ARGS);
1.41 schwarze 62: static void print_man_head(struct termp *, const void *);
63: static void print_man_foot(struct termp *, const void *);
1.100 schwarze 64: static void print_bvspace(struct termp *,
1.88 schwarze 65: const struct man_node *, int);
1.18 schwarze 66:
1.1 kristaps 67: static int pre_B(DECL_ARGS);
1.11 schwarze 68: static int pre_HP(DECL_ARGS);
1.1 kristaps 69: static int pre_I(DECL_ARGS);
70: static int pre_IP(DECL_ARGS);
1.82 schwarze 71: static int pre_OP(DECL_ARGS);
1.88 schwarze 72: static int pre_PD(DECL_ARGS);
1.1 kristaps 73: static int pre_PP(DECL_ARGS);
1.13 schwarze 74: static int pre_RS(DECL_ARGS);
1.1 kristaps 75: static int pre_SH(DECL_ARGS);
76: static int pre_SS(DECL_ARGS);
77: static int pre_TP(DECL_ARGS);
1.91 schwarze 78: static int pre_UR(DECL_ARGS);
1.82 schwarze 79: static int pre_alternate(DECL_ARGS);
80: static int pre_ft(DECL_ARGS);
1.14 schwarze 81: static int pre_ign(DECL_ARGS);
1.45 schwarze 82: static int pre_in(DECL_ARGS);
83: static int pre_literal(DECL_ARGS);
1.97 schwarze 84: static int pre_ll(DECL_ARGS);
1.11 schwarze 85: static int pre_sp(DECL_ARGS);
1.1 kristaps 86:
1.11 schwarze 87: static void post_IP(DECL_ARGS);
88: static void post_HP(DECL_ARGS);
1.13 schwarze 89: static void post_RS(DECL_ARGS);
1.1 kristaps 90: static void post_SH(DECL_ARGS);
91: static void post_SS(DECL_ARGS);
1.11 schwarze 92: static void post_TP(DECL_ARGS);
1.91 schwarze 93: static void post_UR(DECL_ARGS);
1.1 kristaps 94:
1.17 schwarze 95: static const struct termact termacts[MAN_MAX] = {
1.45 schwarze 96: { pre_sp, NULL, MAN_NOTEXT }, /* br */
1.26 schwarze 97: { NULL, NULL, 0 }, /* TH */
98: { pre_SH, post_SH, 0 }, /* SH */
99: { pre_SS, post_SS, 0 }, /* SS */
100: { pre_TP, post_TP, 0 }, /* TP */
101: { pre_PP, NULL, 0 }, /* LP */
102: { pre_PP, NULL, 0 }, /* PP */
103: { pre_PP, NULL, 0 }, /* P */
104: { pre_IP, post_IP, 0 }, /* IP */
1.100 schwarze 105: { pre_HP, post_HP, 0 }, /* HP */
1.26 schwarze 106: { NULL, NULL, 0 }, /* SM */
107: { pre_B, NULL, 0 }, /* SB */
1.51 schwarze 108: { pre_alternate, NULL, 0 }, /* BI */
109: { pre_alternate, NULL, 0 }, /* IB */
110: { pre_alternate, NULL, 0 }, /* BR */
111: { pre_alternate, NULL, 0 }, /* RB */
1.26 schwarze 112: { NULL, NULL, 0 }, /* R */
113: { pre_B, NULL, 0 }, /* B */
114: { pre_I, NULL, 0 }, /* I */
1.51 schwarze 115: { pre_alternate, NULL, 0 }, /* IR */
116: { pre_alternate, NULL, 0 }, /* RI */
1.62 schwarze 117: { pre_ign, NULL, MAN_NOTEXT }, /* na */
1.26 schwarze 118: { pre_sp, NULL, MAN_NOTEXT }, /* sp */
1.45 schwarze 119: { pre_literal, NULL, 0 }, /* nf */
120: { pre_literal, NULL, 0 }, /* fi */
1.26 schwarze 121: { NULL, NULL, 0 }, /* RE */
122: { pre_RS, post_RS, 0 }, /* RS */
123: { pre_ign, NULL, 0 }, /* DT */
1.111 schwarze 124: { pre_ign, NULL, MAN_NOTEXT }, /* UC */
1.88 schwarze 125: { pre_PD, NULL, MAN_NOTEXT }, /* PD */
1.36 schwarze 126: { pre_ign, NULL, 0 }, /* AT */
1.45 schwarze 127: { pre_in, NULL, MAN_NOTEXT }, /* in */
1.52 schwarze 128: { pre_ft, NULL, MAN_NOTEXT }, /* ft */
1.82 schwarze 129: { pre_OP, NULL, 0 }, /* OP */
1.83 schwarze 130: { pre_literal, NULL, 0 }, /* EX */
131: { pre_literal, NULL, 0 }, /* EE */
1.91 schwarze 132: { pre_UR, post_UR, 0 }, /* UR */
133: { NULL, NULL, 0 }, /* UE */
1.97 schwarze 134: { pre_ll, NULL, MAN_NOTEXT }, /* ll */
1.1 kristaps 135: };
1.11 schwarze 136:
1.1 kristaps 137:
1.16 schwarze 138: void
1.18 schwarze 139: terminal_man(void *arg, const struct man *man)
1.1 kristaps 140: {
1.18 schwarze 141: struct termp *p;
1.89 schwarze 142: const struct man_meta *meta;
1.104 schwarze 143: struct man_node *n;
1.18 schwarze 144: struct mtermp mt;
145:
146: p = (struct termp *)arg;
147:
1.39 schwarze 148: p->overstep = 0;
1.104 schwarze 149: p->rmargin = p->maxrmargin = p->defrmargin;
1.42 schwarze 150: p->tabwidth = term_len(p, 5);
1.18 schwarze 151:
1.104 schwarze 152: n = man_node(man)->child;
1.89 schwarze 153: meta = man_meta(man);
1.1 kristaps 154:
1.70 schwarze 155: memset(&mt, 0, sizeof(struct mtermp));
156:
1.77 schwarze 157: mt.lmargin[mt.lmargincur] = term_len(p, p->defindent);
158: mt.offset = term_len(p, p->defindent);
1.88 schwarze 159: mt.pardist = 1;
1.11 schwarze 160:
1.104 schwarze 161: if (p->synopsisonly) {
162: while (n != NULL) {
163: if (n->tok == MAN_SH &&
164: n->child->child->type == MAN_TEXT &&
165: !strcmp(n->child->child->string, "SYNOPSIS")) {
166: if (n->child->next->child != NULL)
167: print_man_nodelist(p, &mt,
168: n->child->next->child, meta);
169: term_newln(p);
170: break;
171: }
172: n = n->next;
173: }
174: } else {
175: if (p->defindent == 0)
176: p->defindent = 7;
177: term_begin(p, print_man_head, print_man_foot, meta);
178: p->flags |= TERMP_NOSPACE;
179: if (n != NULL)
180: print_man_nodelist(p, &mt, n, meta);
181: term_end(p);
182: }
1.1 kristaps 183: }
184:
185:
1.42 schwarze 186: static size_t
187: a2height(const struct termp *p, const char *cp)
1.11 schwarze 188: {
1.18 schwarze 189: struct roffsu su;
1.11 schwarze 190:
1.42 schwarze 191: if ( ! a2roffsu(cp, &su, SCALE_VS))
1.69 schwarze 192: SCALE_VS_INIT(&su, atoi(cp));
1.11 schwarze 193:
1.42 schwarze 194: return(term_vspan(p, &su));
1.11 schwarze 195: }
196:
197: static int
1.42 schwarze 198: a2width(const struct termp *p, const char *cp)
1.11 schwarze 199: {
1.18 schwarze 200: struct roffsu su;
1.11 schwarze 201:
1.112 schwarze 202: if ( ! a2roffsu(cp, &su, SCALE_EN))
1.18 schwarze 203: return(-1);
204:
1.42 schwarze 205: return((int)term_hspan(p, &su));
1.18 schwarze 206: }
1.11 schwarze 207:
1.69 schwarze 208: /*
209: * Printing leading vertical space before a block.
210: * This is used for the paragraph macros.
211: * The rules are pretty simple, since there's very little nesting going
212: * on here. Basically, if we're the first within another block (SS/SH),
213: * then don't emit vertical space. If we are (RS), then do. If not the
214: * first, print it.
215: */
1.18 schwarze 216: static void
1.88 schwarze 217: print_bvspace(struct termp *p, const struct man_node *n, int pardist)
1.18 schwarze 218: {
1.88 schwarze 219: int i;
1.69 schwarze 220:
1.18 schwarze 221: term_newln(p);
1.64 schwarze 222:
1.69 schwarze 223: if (n->body && n->body->child)
224: if (MAN_TBL == n->body->child->type)
225: return;
1.11 schwarze 226:
1.69 schwarze 227: if (MAN_ROOT == n->parent->type || MAN_RS != n->parent->tok)
228: if (NULL == n->prev)
229: return;
1.11 schwarze 230:
1.88 schwarze 231: for (i = 0; i < pardist; i++)
232: term_vspace(p);
1.14 schwarze 233: }
234:
1.100 schwarze 235:
1.14 schwarze 236: static int
237: pre_ign(DECL_ARGS)
238: {
239:
1.97 schwarze 240: return(0);
241: }
242:
243: static int
244: pre_ll(DECL_ARGS)
245: {
246:
1.98 schwarze 247: term_setwidth(p, n->nchild ? n->child->string : NULL);
1.14 schwarze 248: return(0);
1.11 schwarze 249: }
250:
1.1 kristaps 251: static int
252: pre_I(DECL_ARGS)
253: {
254:
1.21 schwarze 255: term_fontrepl(p, TERMFONT_UNDER);
1.1 kristaps 256: return(1);
257: }
258:
1.11 schwarze 259: static int
1.45 schwarze 260: pre_literal(DECL_ARGS)
1.11 schwarze 261: {
262:
1.45 schwarze 263: term_newln(p);
1.53 schwarze 264:
1.83 schwarze 265: if (MAN_nf == n->tok || MAN_EX == n->tok)
1.45 schwarze 266: mt->fl |= MANT_LITERAL;
1.53 schwarze 267: else
1.45 schwarze 268: mt->fl &= ~MANT_LITERAL;
269:
1.72 schwarze 270: /*
271: * Unlike .IP and .TP, .HP does not have a HEAD.
272: * So in case a second call to term_flushln() is needed,
273: * indentation has to be set up explicitly.
274: */
275: if (MAN_HP == n->parent->tok && p->rmargin < p->maxrmargin) {
1.76 schwarze 276: p->offset = p->rmargin;
1.72 schwarze 277: p->rmargin = p->maxrmargin;
1.93 schwarze 278: p->trailspace = 0;
1.99 schwarze 279: p->flags &= ~(TERMP_NOBREAK | TERMP_BRIND);
1.72 schwarze 280: p->flags |= TERMP_NOSPACE;
281: }
282:
1.62 schwarze 283: return(0);
1.11 schwarze 284: }
285:
286: static int
1.88 schwarze 287: pre_PD(DECL_ARGS)
288: {
1.113 schwarze 289: struct roffsu su;
1.88 schwarze 290:
291: n = n->child;
1.113 schwarze 292: if (n == NULL) {
1.88 schwarze 293: mt->pardist = 1;
294: return(0);
295: }
296: assert(MAN_TEXT == n->type);
1.113 schwarze 297: if (a2roffsu(n->string, &su, SCALE_VS))
298: mt->pardist = term_vspan(p, &su);
1.88 schwarze 299: return(0);
300: }
301:
302: static int
1.51 schwarze 303: pre_alternate(DECL_ARGS)
1.1 kristaps 304: {
1.51 schwarze 305: enum termfont font[2];
306: const struct man_node *nn;
307: int savelit, i;
1.1 kristaps 308:
1.51 schwarze 309: switch (n->tok) {
1.100 schwarze 310: case MAN_RB:
1.51 schwarze 311: font[0] = TERMFONT_NONE;
312: font[1] = TERMFONT_BOLD;
313: break;
1.100 schwarze 314: case MAN_RI:
1.51 schwarze 315: font[0] = TERMFONT_NONE;
316: font[1] = TERMFONT_UNDER;
317: break;
1.100 schwarze 318: case MAN_BR:
1.51 schwarze 319: font[0] = TERMFONT_BOLD;
320: font[1] = TERMFONT_NONE;
321: break;
1.100 schwarze 322: case MAN_BI:
1.51 schwarze 323: font[0] = TERMFONT_BOLD;
324: font[1] = TERMFONT_UNDER;
325: break;
1.100 schwarze 326: case MAN_IR:
1.51 schwarze 327: font[0] = TERMFONT_UNDER;
328: font[1] = TERMFONT_NONE;
329: break;
1.100 schwarze 330: case MAN_IB:
1.51 schwarze 331: font[0] = TERMFONT_UNDER;
332: font[1] = TERMFONT_BOLD;
333: break;
334: default:
335: abort();
336: }
1.17 schwarze 337:
1.51 schwarze 338: savelit = MANT_LITERAL & mt->fl;
339: mt->fl &= ~MANT_LITERAL;
1.17 schwarze 340:
1.51 schwarze 341: for (i = 0, nn = n->child; nn; nn = nn->next, i = 1 - i) {
342: term_fontrepl(p, font[i]);
343: if (savelit && NULL == nn->next)
344: mt->fl |= MANT_LITERAL;
1.89 schwarze 345: print_man_node(p, mt, nn, meta);
1.51 schwarze 346: if (nn->next)
1.1 kristaps 347: p->flags |= TERMP_NOSPACE;
348: }
1.17 schwarze 349:
1.1 kristaps 350: return(0);
351: }
352:
353: static int
354: pre_B(DECL_ARGS)
355: {
356:
1.21 schwarze 357: term_fontrepl(p, TERMFONT_BOLD);
1.1 kristaps 358: return(1);
1.82 schwarze 359: }
360:
361: static int
362: pre_OP(DECL_ARGS)
363: {
364:
365: term_word(p, "[");
366: p->flags |= TERMP_NOSPACE;
367:
368: if (NULL != (n = n->child)) {
369: term_fontrepl(p, TERMFONT_BOLD);
370: term_word(p, n->string);
371: }
372: if (NULL != n && NULL != n->next) {
373: term_fontrepl(p, TERMFONT_UNDER);
374: term_word(p, n->next->string);
375: }
376:
377: term_fontrepl(p, TERMFONT_NONE);
378: p->flags |= TERMP_NOSPACE;
379: term_word(p, "]");
380: return(0);
1.52 schwarze 381: }
382:
383: static int
384: pre_ft(DECL_ARGS)
385: {
386: const char *cp;
387:
388: if (NULL == n->child) {
389: term_fontlast(p);
390: return(0);
391: }
392:
393: cp = n->child->string;
394: switch (*cp) {
1.100 schwarze 395: case '4':
1.52 schwarze 396: /* FALLTHROUGH */
1.100 schwarze 397: case '3':
1.52 schwarze 398: /* FALLTHROUGH */
1.100 schwarze 399: case 'B':
1.52 schwarze 400: term_fontrepl(p, TERMFONT_BOLD);
401: break;
1.100 schwarze 402: case '2':
1.52 schwarze 403: /* FALLTHROUGH */
1.100 schwarze 404: case 'I':
1.52 schwarze 405: term_fontrepl(p, TERMFONT_UNDER);
406: break;
1.100 schwarze 407: case 'P':
1.52 schwarze 408: term_fontlast(p);
409: break;
1.100 schwarze 410: case '1':
1.52 schwarze 411: /* FALLTHROUGH */
1.100 schwarze 412: case 'C':
1.52 schwarze 413: /* FALLTHROUGH */
1.100 schwarze 414: case 'R':
1.52 schwarze 415: term_fontrepl(p, TERMFONT_NONE);
416: break;
417: default:
418: break;
419: }
420: return(0);
1.1 kristaps 421: }
422:
423: static int
1.45 schwarze 424: pre_in(DECL_ARGS)
1.11 schwarze 425: {
1.45 schwarze 426: int len, less;
427: size_t v;
428: const char *cp;
429:
430: term_newln(p);
431:
432: if (NULL == n->child) {
433: p->offset = mt->offset;
434: return(0);
435: }
1.11 schwarze 436:
1.45 schwarze 437: cp = n->child->string;
438: less = 0;
1.11 schwarze 439:
1.45 schwarze 440: if ('-' == *cp)
441: less = -1;
442: else if ('+' == *cp)
443: less = 1;
444: else
445: cp--;
446:
447: if ((len = a2width(p, ++cp)) < 0)
448: return(0);
449:
450: v = (size_t)len;
451:
452: if (less < 0)
453: p->offset -= p->offset > v ? v : p->offset;
454: else if (less > 0)
455: p->offset += v;
1.100 schwarze 456: else
1.45 schwarze 457: p->offset = v;
1.59 schwarze 458:
1.11 schwarze 459: return(0);
460: }
461:
462: static int
1.45 schwarze 463: pre_sp(DECL_ARGS)
1.8 schwarze 464: {
1.85 schwarze 465: char *s;
1.45 schwarze 466: size_t i, len;
1.85 schwarze 467: int neg;
1.45 schwarze 468:
1.69 schwarze 469: if ((NULL == n->prev && n->parent)) {
1.86 schwarze 470: switch (n->parent->tok) {
1.100 schwarze 471: case MAN_SH:
1.86 schwarze 472: /* FALLTHROUGH */
1.100 schwarze 473: case MAN_SS:
1.86 schwarze 474: /* FALLTHROUGH */
1.100 schwarze 475: case MAN_PP:
1.86 schwarze 476: /* FALLTHROUGH */
1.100 schwarze 477: case MAN_LP:
1.86 schwarze 478: /* FALLTHROUGH */
1.100 schwarze 479: case MAN_P:
1.86 schwarze 480: /* FALLTHROUGH */
1.69 schwarze 481: return(0);
1.86 schwarze 482: default:
483: break;
484: }
1.69 schwarze 485: }
486:
1.85 schwarze 487: neg = 0;
1.45 schwarze 488: switch (n->tok) {
1.100 schwarze 489: case MAN_br:
1.45 schwarze 490: len = 0;
491: break;
492: default:
1.85 schwarze 493: if (NULL == n->child) {
494: len = 1;
495: break;
496: }
497: s = n->child->string;
498: if ('-' == *s) {
499: neg = 1;
500: s++;
501: }
502: len = a2height(p, s);
1.45 schwarze 503: break;
504: }
505:
506: if (0 == len)
507: term_newln(p);
1.85 schwarze 508: else if (neg)
509: p->skipvsp += len;
510: else
511: for (i = 0; i < len; i++)
512: term_vspace(p);
1.8 schwarze 513:
514: return(0);
515: }
516:
517: static int
1.11 schwarze 518: pre_HP(DECL_ARGS)
519: {
1.72 schwarze 520: size_t len, one;
1.11 schwarze 521: int ival;
522: const struct man_node *nn;
523:
524: switch (n->type) {
1.100 schwarze 525: case MAN_BLOCK:
1.88 schwarze 526: print_bvspace(p, n, mt->pardist);
1.11 schwarze 527: return(1);
1.100 schwarze 528: case MAN_BODY:
1.11 schwarze 529: break;
530: default:
531: return(0);
532: }
533:
1.84 schwarze 534: if ( ! (MANT_LITERAL & mt->fl)) {
1.99 schwarze 535: p->flags |= TERMP_NOBREAK | TERMP_BRIND;
1.93 schwarze 536: p->trailspace = 2;
1.84 schwarze 537: }
538:
1.70 schwarze 539: len = mt->lmargin[mt->lmargincur];
1.11 schwarze 540: ival = -1;
541:
542: /* Calculate offset. */
543:
544: if (NULL != (nn = n->parent->head->child))
1.42 schwarze 545: if ((ival = a2width(p, nn->string)) >= 0)
1.11 schwarze 546: len = (size_t)ival;
547:
1.72 schwarze 548: one = term_len(p, 1);
1.76 schwarze 549: if (len < one)
1.72 schwarze 550: len = one;
1.11 schwarze 551:
1.13 schwarze 552: p->offset = mt->offset;
553: p->rmargin = mt->offset + len;
1.11 schwarze 554:
555: if (ival >= 0)
1.70 schwarze 556: mt->lmargin[mt->lmargincur] = (size_t)ival;
1.11 schwarze 557:
558: return(1);
559: }
560:
561: static void
562: post_HP(DECL_ARGS)
563: {
564:
565: switch (n->type) {
1.100 schwarze 566: case MAN_BODY:
1.90 schwarze 567: term_newln(p);
1.99 schwarze 568: p->flags &= ~(TERMP_NOBREAK | TERMP_BRIND);
1.93 schwarze 569: p->trailspace = 0;
1.13 schwarze 570: p->offset = mt->offset;
1.11 schwarze 571: p->rmargin = p->maxrmargin;
572: break;
573: default:
574: break;
575: }
576: }
577:
578: static int
1.1 kristaps 579: pre_PP(DECL_ARGS)
580: {
581:
1.11 schwarze 582: switch (n->type) {
1.100 schwarze 583: case MAN_BLOCK:
1.77 schwarze 584: mt->lmargin[mt->lmargincur] = term_len(p, p->defindent);
1.88 schwarze 585: print_bvspace(p, n, mt->pardist);
1.11 schwarze 586: break;
587: default:
1.13 schwarze 588: p->offset = mt->offset;
1.11 schwarze 589: break;
590: }
591:
1.54 schwarze 592: return(MAN_HEAD != n->type);
1.1 kristaps 593: }
594:
595: static int
596: pre_IP(DECL_ARGS)
597: {
1.11 schwarze 598: const struct man_node *nn;
599: size_t len;
1.57 schwarze 600: int savelit, ival;
1.11 schwarze 601:
602: switch (n->type) {
1.100 schwarze 603: case MAN_BODY:
1.11 schwarze 604: p->flags |= TERMP_NOSPACE;
605: break;
1.100 schwarze 606: case MAN_HEAD:
1.11 schwarze 607: p->flags |= TERMP_NOBREAK;
1.93 schwarze 608: p->trailspace = 1;
1.11 schwarze 609: break;
1.100 schwarze 610: case MAN_BLOCK:
1.88 schwarze 611: print_bvspace(p, n, mt->pardist);
1.11 schwarze 612: /* FALLTHROUGH */
613: default:
614: return(1);
615: }
616:
1.70 schwarze 617: len = mt->lmargin[mt->lmargincur];
1.11 schwarze 618: ival = -1;
619:
1.57 schwarze 620: /* Calculate the offset from the optional second argument. */
1.11 schwarze 621: if (NULL != (nn = n->parent->head->child))
1.57 schwarze 622: if (NULL != (nn = nn->next))
1.42 schwarze 623: if ((ival = a2width(p, nn->string)) >= 0)
1.11 schwarze 624: len = (size_t)ival;
625:
626: switch (n->type) {
1.100 schwarze 627: case MAN_HEAD:
1.11 schwarze 628: /* Handle zero-width lengths. */
629: if (0 == len)
1.42 schwarze 630: len = term_len(p, 1);
1.11 schwarze 631:
1.13 schwarze 632: p->offset = mt->offset;
633: p->rmargin = mt->offset + len;
1.11 schwarze 634:
635: /* Set the saved left-margin. */
1.114 ! schwarze 636: if (ival >= 0)
! 637: mt->lmargin[mt->lmargincur] = (size_t)ival;
1.1 kristaps 638:
1.57 schwarze 639: savelit = MANT_LITERAL & mt->fl;
640: mt->fl &= ~MANT_LITERAL;
641:
642: if (n->child)
1.89 schwarze 643: print_man_node(p, mt, n->child, meta);
1.57 schwarze 644:
645: if (savelit)
646: mt->fl |= MANT_LITERAL;
647:
1.11 schwarze 648: return(0);
1.100 schwarze 649: case MAN_BODY:
1.13 schwarze 650: p->offset = mt->offset + len;
1.109 schwarze 651: p->rmargin = p->maxrmargin;
1.11 schwarze 652: break;
653: default:
654: break;
655: }
1.1 kristaps 656:
1.11 schwarze 657: return(1);
658: }
1.1 kristaps 659:
1.11 schwarze 660: static void
661: post_IP(DECL_ARGS)
662: {
1.4 schwarze 663:
1.11 schwarze 664: switch (n->type) {
1.100 schwarze 665: case MAN_HEAD:
1.11 schwarze 666: term_flushln(p);
667: p->flags &= ~TERMP_NOBREAK;
1.93 schwarze 668: p->trailspace = 0;
1.11 schwarze 669: p->rmargin = p->maxrmargin;
670: break;
1.100 schwarze 671: case MAN_BODY:
1.57 schwarze 672: term_newln(p);
1.92 schwarze 673: p->offset = mt->offset;
1.11 schwarze 674: break;
675: default:
676: break;
677: }
1.1 kristaps 678: }
679:
680: static int
681: pre_TP(DECL_ARGS)
682: {
1.11 schwarze 683: const struct man_node *nn;
684: size_t len;
1.57 schwarze 685: int savelit, ival;
1.11 schwarze 686:
687: switch (n->type) {
1.100 schwarze 688: case MAN_HEAD:
1.11 schwarze 689: p->flags |= TERMP_NOBREAK;
1.93 schwarze 690: p->trailspace = 1;
1.11 schwarze 691: break;
1.100 schwarze 692: case MAN_BODY:
1.11 schwarze 693: p->flags |= TERMP_NOSPACE;
694: break;
1.100 schwarze 695: case MAN_BLOCK:
1.88 schwarze 696: print_bvspace(p, n, mt->pardist);
1.11 schwarze 697: /* FALLTHROUGH */
698: default:
699: return(1);
700: }
701:
1.70 schwarze 702: len = (size_t)mt->lmargin[mt->lmargincur];
1.11 schwarze 703: ival = -1;
704:
705: /* Calculate offset. */
1.1 kristaps 706:
1.70 schwarze 707: if (NULL != (nn = n->parent->head->child))
1.95 schwarze 708: if (nn->string && 0 == (MAN_LINE & nn->flags))
1.42 schwarze 709: if ((ival = a2width(p, nn->string)) >= 0)
1.11 schwarze 710: len = (size_t)ival;
1.8 schwarze 711:
1.11 schwarze 712: switch (n->type) {
1.100 schwarze 713: case MAN_HEAD:
1.11 schwarze 714: /* Handle zero-length properly. */
715: if (0 == len)
1.42 schwarze 716: len = term_len(p, 1);
1.11 schwarze 717:
1.13 schwarze 718: p->offset = mt->offset;
719: p->rmargin = mt->offset + len;
1.11 schwarze 720:
1.57 schwarze 721: savelit = MANT_LITERAL & mt->fl;
722: mt->fl &= ~MANT_LITERAL;
723:
1.11 schwarze 724: /* Don't print same-line elements. */
1.95 schwarze 725: nn = n->child;
726: while (NULL != nn && 0 == (MAN_LINE & nn->flags))
727: nn = nn->next;
728:
729: while (NULL != nn) {
730: print_man_node(p, mt, nn, meta);
731: nn = nn->next;
732: }
1.11 schwarze 733:
1.57 schwarze 734: if (savelit)
735: mt->fl |= MANT_LITERAL;
1.11 schwarze 736: if (ival >= 0)
1.70 schwarze 737: mt->lmargin[mt->lmargincur] = (size_t)ival;
1.11 schwarze 738:
739: return(0);
1.100 schwarze 740: case MAN_BODY:
1.13 schwarze 741: p->offset = mt->offset + len;
1.109 schwarze 742: p->rmargin = p->maxrmargin;
1.93 schwarze 743: p->trailspace = 0;
1.84 schwarze 744: p->flags &= ~TERMP_NOBREAK;
1.11 schwarze 745: break;
746: default:
747: break;
748: }
1.1 kristaps 749:
1.11 schwarze 750: return(1);
751: }
1.1 kristaps 752:
1.11 schwarze 753: static void
754: post_TP(DECL_ARGS)
755: {
1.1 kristaps 756:
1.11 schwarze 757: switch (n->type) {
1.100 schwarze 758: case MAN_HEAD:
1.11 schwarze 759: term_flushln(p);
760: break;
1.100 schwarze 761: case MAN_BODY:
1.57 schwarze 762: term_newln(p);
1.92 schwarze 763: p->offset = mt->offset;
1.11 schwarze 764: break;
765: default:
766: break;
767: }
1.1 kristaps 768: }
769:
770: static int
771: pre_SS(DECL_ARGS)
772: {
1.88 schwarze 773: int i;
1.1 kristaps 774:
1.11 schwarze 775: switch (n->type) {
1.100 schwarze 776: case MAN_BLOCK:
1.69 schwarze 777: mt->fl &= ~MANT_LITERAL;
1.77 schwarze 778: mt->lmargin[mt->lmargincur] = term_len(p, p->defindent);
779: mt->offset = term_len(p, p->defindent);
1.111 schwarze 780:
781: /*
782: * No vertical space before the first subsection
783: * and after an empty subsection.
784: */
785:
786: do {
787: n = n->prev;
788: } while (n != NULL && termacts[n->tok].flags & MAN_NOTEXT);
789: if (n == NULL || (n->tok == MAN_SS && n->body->child == NULL))
1.11 schwarze 790: break;
1.111 schwarze 791:
1.88 schwarze 792: for (i = 0; i < mt->pardist; i++)
793: term_vspace(p);
1.11 schwarze 794: break;
1.100 schwarze 795: case MAN_HEAD:
1.21 schwarze 796: term_fontrepl(p, TERMFONT_BOLD);
1.87 schwarze 797: p->offset = term_len(p, 3);
1.11 schwarze 798: break;
1.100 schwarze 799: case MAN_BODY:
1.13 schwarze 800: p->offset = mt->offset;
1.11 schwarze 801: break;
802: default:
803: break;
804: }
805:
1.1 kristaps 806: return(1);
807: }
808:
809: static void
810: post_SS(DECL_ARGS)
811: {
1.100 schwarze 812:
1.11 schwarze 813: switch (n->type) {
1.100 schwarze 814: case MAN_HEAD:
1.11 schwarze 815: term_newln(p);
816: break;
1.100 schwarze 817: case MAN_BODY:
1.11 schwarze 818: term_newln(p);
819: break;
820: default:
821: break;
822: }
1.1 kristaps 823: }
824:
825: static int
826: pre_SH(DECL_ARGS)
827: {
1.88 schwarze 828: int i;
1.1 kristaps 829:
1.11 schwarze 830: switch (n->type) {
1.100 schwarze 831: case MAN_BLOCK:
1.69 schwarze 832: mt->fl &= ~MANT_LITERAL;
1.77 schwarze 833: mt->lmargin[mt->lmargincur] = term_len(p, p->defindent);
834: mt->offset = term_len(p, p->defindent);
1.111 schwarze 835:
836: /*
837: * No vertical space before the first section
838: * and after an empty section.
839: */
840:
841: do {
842: n = n->prev;
843: } while (n != NULL && termacts[n->tok].flags & MAN_NOTEXT);
844: if (n == NULL || (n->tok == MAN_SH && n->body->child == NULL))
1.29 schwarze 845: break;
1.111 schwarze 846:
1.88 schwarze 847: for (i = 0; i < mt->pardist; i++)
848: term_vspace(p);
1.11 schwarze 849: break;
1.100 schwarze 850: case MAN_HEAD:
1.21 schwarze 851: term_fontrepl(p, TERMFONT_BOLD);
1.11 schwarze 852: p->offset = 0;
853: break;
1.100 schwarze 854: case MAN_BODY:
1.13 schwarze 855: p->offset = mt->offset;
1.11 schwarze 856: break;
857: default:
858: break;
859: }
860:
1.1 kristaps 861: return(1);
862: }
863:
864: static void
865: post_SH(DECL_ARGS)
866: {
1.100 schwarze 867:
1.11 schwarze 868: switch (n->type) {
1.100 schwarze 869: case MAN_HEAD:
1.11 schwarze 870: term_newln(p);
871: break;
1.100 schwarze 872: case MAN_BODY:
1.11 schwarze 873: term_newln(p);
874: break;
875: default:
1.13 schwarze 876: break;
877: }
878: }
879:
880: static int
881: pre_RS(DECL_ARGS)
882: {
1.69 schwarze 883: int ival;
884: size_t sz;
1.13 schwarze 885:
886: switch (n->type) {
1.100 schwarze 887: case MAN_BLOCK:
1.13 schwarze 888: term_newln(p);
889: return(1);
1.100 schwarze 890: case MAN_HEAD:
1.13 schwarze 891: return(0);
892: default:
893: break;
894: }
895:
1.77 schwarze 896: sz = term_len(p, p->defindent);
1.13 schwarze 897:
1.69 schwarze 898: if (NULL != (n = n->parent->head->child))
1.100 schwarze 899: if ((ival = a2width(p, n->string)) >= 0)
1.69 schwarze 900: sz = (size_t)ival;
1.13 schwarze 901:
1.69 schwarze 902: mt->offset += sz;
1.94 schwarze 903: p->offset = mt->offset;
1.109 schwarze 904: p->rmargin = p->maxrmargin;
1.13 schwarze 905:
1.70 schwarze 906: if (++mt->lmarginsz < MAXMARGINS)
907: mt->lmargincur = mt->lmarginsz;
908:
909: mt->lmargin[mt->lmargincur] = mt->lmargin[mt->lmargincur - 1];
1.13 schwarze 910: return(1);
911: }
912:
913: static void
914: post_RS(DECL_ARGS)
915: {
1.69 schwarze 916: int ival;
917: size_t sz;
1.13 schwarze 918:
919: switch (n->type) {
1.100 schwarze 920: case MAN_BLOCK:
1.69 schwarze 921: return;
1.100 schwarze 922: case MAN_HEAD:
1.69 schwarze 923: return;
1.13 schwarze 924: default:
925: term_newln(p);
1.11 schwarze 926: break;
927: }
1.69 schwarze 928:
1.77 schwarze 929: sz = term_len(p, p->defindent);
1.69 schwarze 930:
1.100 schwarze 931: if (NULL != (n = n->parent->head->child))
932: if ((ival = a2width(p, n->string)) >= 0)
1.69 schwarze 933: sz = (size_t)ival;
934:
935: mt->offset = mt->offset < sz ? 0 : mt->offset - sz;
936: p->offset = mt->offset;
1.70 schwarze 937:
938: if (--mt->lmarginsz < MAXMARGINS)
939: mt->lmargincur = mt->lmarginsz;
1.91 schwarze 940: }
941:
942: static int
943: pre_UR(DECL_ARGS)
944: {
945:
946: return (MAN_HEAD != n->type);
947: }
948:
949: static void
950: post_UR(DECL_ARGS)
951: {
952:
953: if (MAN_BLOCK != n->type)
954: return;
955:
956: term_word(p, "<");
957: p->flags |= TERMP_NOSPACE;
958:
959: if (NULL != n->child->child)
960: print_man_node(p, mt, n->child->child, meta);
961:
962: p->flags |= TERMP_NOSPACE;
963: term_word(p, ">");
1.47 schwarze 964: }
965:
1.1 kristaps 966: static void
1.19 schwarze 967: print_man_node(DECL_ARGS)
1.1 kristaps 968: {
1.32 schwarze 969: size_t rm, rmax;
1.21 schwarze 970: int c;
1.1 kristaps 971:
972: switch (n->type) {
1.100 schwarze 973: case MAN_TEXT:
1.61 schwarze 974: /*
975: * If we have a blank line, output a vertical space.
976: * If we have a space as the first character, break
977: * before printing the line's data.
978: */
1.60 schwarze 979: if ('\0' == *n->string) {
1.1 kristaps 980: term_vspace(p);
1.61 schwarze 981: return;
982: } else if (' ' == *n->string && MAN_LINE & n->flags)
1.60 schwarze 983: term_newln(p);
1.21 schwarze 984:
1.1 kristaps 985: term_word(p, n->string);
1.84 schwarze 986: goto out;
1.21 schwarze 987:
1.100 schwarze 988: case MAN_EQN:
1.105 schwarze 989: if ( ! (n->flags & MAN_LINE))
990: p->flags |= TERMP_NOSPACE;
1.71 schwarze 991: term_eqn(p, n->eqn);
1.107 schwarze 992: if (n->next != NULL && ! (n->next->flags & MAN_LINE))
1.106 schwarze 993: p->flags |= TERMP_NOSPACE;
1.61 schwarze 994: return;
1.100 schwarze 995: case MAN_TBL:
1.61 schwarze 996: /*
997: * Tables are preceded by a newline. Then process a
998: * table line, which will cause line termination,
999: */
1.100 schwarze 1000: if (TBL_SPAN_FIRST & n->span->flags)
1.58 schwarze 1001: term_newln(p);
1002: term_tbl(p, n->span);
1.61 schwarze 1003: return;
1.1 kristaps 1004: default:
1005: break;
1006: }
1007:
1.61 schwarze 1008: if ( ! (MAN_NOTEXT & termacts[n->tok].flags))
1009: term_fontrepl(p, TERMFONT_NONE);
1010:
1011: c = 1;
1012: if (termacts[n->tok].pre)
1.89 schwarze 1013: c = (*termacts[n->tok].pre)(p, mt, n, meta);
1.61 schwarze 1014:
1.1 kristaps 1015: if (c && n->child)
1.89 schwarze 1016: print_man_nodelist(p, mt, n->child, meta);
1.1 kristaps 1017:
1.61 schwarze 1018: if (termacts[n->tok].post)
1.89 schwarze 1019: (*termacts[n->tok].post)(p, mt, n, meta);
1.61 schwarze 1020: if ( ! (MAN_NOTEXT & termacts[n->tok].flags))
1021: term_fontrepl(p, TERMFONT_NONE);
1.30 schwarze 1022:
1.84 schwarze 1023: out:
1024: /*
1025: * If we're in a literal context, make sure that words
1026: * together on the same line stay together. This is a
1027: * POST-printing call, so we check the NEXT word. Since
1028: * -man doesn't have nested macros, we don't need to be
1029: * more specific than this.
1030: */
1.110 schwarze 1031: if (mt->fl & MANT_LITERAL &&
1032: ! (p->flags & (TERMP_NOBREAK | TERMP_NONEWLINE)) &&
1033: (n->next == NULL || n->next->flags & MAN_LINE)) {
1.84 schwarze 1034: rm = p->rmargin;
1035: rmax = p->maxrmargin;
1036: p->rmargin = p->maxrmargin = TERM_MAXMARGIN;
1037: p->flags |= TERMP_NOSPACE;
1.110 schwarze 1038: if (n->string != NULL && *n->string != '\0')
1.84 schwarze 1039: term_flushln(p);
1040: else
1041: term_newln(p);
1042: if (rm < rmax && n->parent->tok == MAN_HP) {
1043: p->offset = rm;
1044: p->rmargin = rmax;
1045: } else
1046: p->rmargin = rm;
1047: p->maxrmargin = rmax;
1048: }
1.30 schwarze 1049: if (MAN_EOS & n->flags)
1050: p->flags |= TERMP_SENTENCE;
1.1 kristaps 1051: }
1052:
1053:
1054: static void
1.21 schwarze 1055: print_man_nodelist(DECL_ARGS)
1.1 kristaps 1056: {
1.11 schwarze 1057:
1.89 schwarze 1058: print_man_node(p, mt, n, meta);
1.1 kristaps 1059: if ( ! n->next)
1060: return;
1.89 schwarze 1061: print_man_nodelist(p, mt, n->next, meta);
1.1 kristaps 1062: }
1063:
1064: static void
1.41 schwarze 1065: print_man_foot(struct termp *p, const void *arg)
1.1 kristaps 1066: {
1.101 schwarze 1067: const struct man_meta *meta;
1068: char *title;
1.109 schwarze 1069: size_t datelen, titlen;
1.41 schwarze 1070:
1071: meta = (const struct man_meta *)arg;
1.80 schwarze 1072: assert(meta->title);
1073: assert(meta->msec);
1074: assert(meta->date);
1.21 schwarze 1075:
1076: term_fontrepl(p, TERMFONT_NONE);
1.1 kristaps 1077:
1.103 schwarze 1078: if (meta->hasbody)
1079: term_vspace(p);
1.81 schwarze 1080:
1081: /*
1082: * Temporary, undocumented option to imitate mdoc(7) output.
1083: * In the bottom right corner, use the source instead of
1084: * the title.
1085: */
1086:
1.79 schwarze 1087: if ( ! p->mdocstyle) {
1.103 schwarze 1088: if (meta->hasbody) {
1089: term_vspace(p);
1090: term_vspace(p);
1091: }
1.101 schwarze 1092: mandoc_asprintf(&title, "%s(%s)",
1093: meta->title, meta->msec);
1.79 schwarze 1094: } else if (meta->source) {
1.101 schwarze 1095: title = mandoc_strdup(meta->source);
1.79 schwarze 1096: } else {
1.101 schwarze 1097: title = mandoc_strdup("");
1.79 schwarze 1098: }
1.78 schwarze 1099: datelen = term_strlen(p, meta->date);
1.1 kristaps 1100:
1.81 schwarze 1101: /* Bottom left corner: manual source. */
1102:
1.1 kristaps 1103: p->flags |= TERMP_NOSPACE | TERMP_NOBREAK;
1.93 schwarze 1104: p->trailspace = 1;
1.1 kristaps 1105: p->offset = 0;
1.109 schwarze 1106: p->rmargin = p->maxrmargin > datelen ?
1107: (p->maxrmargin + term_len(p, 1) - datelen) / 2 : 0;
1.1 kristaps 1108:
1109: if (meta->source)
1110: term_word(p, meta->source);
1111: term_flushln(p);
1112:
1.81 schwarze 1113: /* At the bottom in the middle: manual date. */
1114:
1.109 schwarze 1115: p->offset = p->rmargin;
1116: titlen = term_strlen(p, title);
1117: p->rmargin = p->maxrmargin > titlen ? p->maxrmargin - titlen : 0;
1.72 schwarze 1118: p->flags |= TERMP_NOSPACE;
1.78 schwarze 1119:
1120: term_word(p, meta->date);
1121: term_flushln(p);
1122:
1.81 schwarze 1123: /* Bottom right corner: manual title and section. */
1124:
1.78 schwarze 1125: p->flags &= ~TERMP_NOBREAK;
1126: p->flags |= TERMP_NOSPACE;
1.93 schwarze 1127: p->trailspace = 0;
1.78 schwarze 1128: p->offset = p->rmargin;
1.1 kristaps 1129: p->rmargin = p->maxrmargin;
1130:
1.78 schwarze 1131: term_word(p, title);
1.1 kristaps 1132: term_flushln(p);
1.101 schwarze 1133: free(title);
1.1 kristaps 1134: }
1135:
1136: static void
1.41 schwarze 1137: print_man_head(struct termp *p, const void *arg)
1.1 kristaps 1138: {
1.101 schwarze 1139: const struct man_meta *meta;
1.102 schwarze 1140: const char *volume;
1.101 schwarze 1141: char *title;
1.102 schwarze 1142: size_t vollen, titlen;
1.41 schwarze 1143:
1.89 schwarze 1144: meta = (const struct man_meta *)arg;
1145: assert(meta->title);
1146: assert(meta->msec);
1.1 kristaps 1147:
1.102 schwarze 1148: volume = NULL == meta->vol ? "" : meta->vol;
1149: vollen = term_strlen(p, volume);
1.1 kristaps 1150:
1.81 schwarze 1151: /* Top left corner: manual title and section. */
1152:
1.101 schwarze 1153: mandoc_asprintf(&title, "%s(%s)", meta->title, meta->msec);
1.42 schwarze 1154: titlen = term_strlen(p, title);
1.1 kristaps 1155:
1.73 schwarze 1156: p->flags |= TERMP_NOBREAK | TERMP_NOSPACE;
1.93 schwarze 1157: p->trailspace = 1;
1.1 kristaps 1158: p->offset = 0;
1.102 schwarze 1159: p->rmargin = 2 * (titlen+1) + vollen < p->maxrmargin ?
1160: (p->maxrmargin - vollen + term_len(p, 1)) / 2 :
1.109 schwarze 1161: vollen < p->maxrmargin ? p->maxrmargin - vollen : 0;
1.1 kristaps 1162:
1163: term_word(p, title);
1164: term_flushln(p);
1165:
1.81 schwarze 1166: /* At the top in the middle: manual volume. */
1167:
1.72 schwarze 1168: p->flags |= TERMP_NOSPACE;
1.1 kristaps 1169: p->offset = p->rmargin;
1.102 schwarze 1170: p->rmargin = p->offset + vollen + titlen < p->maxrmargin ?
1.25 schwarze 1171: p->maxrmargin - titlen : p->maxrmargin;
1.1 kristaps 1172:
1.102 schwarze 1173: term_word(p, volume);
1.1 kristaps 1174: term_flushln(p);
1175:
1.81 schwarze 1176: /* Top right corner: title and section, again. */
1177:
1.1 kristaps 1178: p->flags &= ~TERMP_NOBREAK;
1.93 schwarze 1179: p->trailspace = 0;
1.25 schwarze 1180: if (p->rmargin + titlen <= p->maxrmargin) {
1.72 schwarze 1181: p->flags |= TERMP_NOSPACE;
1.25 schwarze 1182: p->offset = p->rmargin;
1183: p->rmargin = p->maxrmargin;
1184: term_word(p, title);
1185: term_flushln(p);
1186: }
1.1 kristaps 1187:
1.73 schwarze 1188: p->flags &= ~TERMP_NOSPACE;
1189: p->offset = 0;
1.1 kristaps 1190: p->rmargin = p->maxrmargin;
1.29 schwarze 1191:
1.100 schwarze 1192: /*
1.81 schwarze 1193: * Groff prints three blank lines before the content.
1194: * Do the same, except in the temporary, undocumented
1195: * mode imitating mdoc(7) output.
1.29 schwarze 1196: */
1197:
1198: term_vspace(p);
1.79 schwarze 1199: if ( ! p->mdocstyle) {
1200: term_vspace(p);
1201: term_vspace(p);
1202: }
1.101 schwarze 1203: free(title);
1.1 kristaps 1204: }