Lines Matching +full:n +full:-
3 * Copyright (c) 2010, 2012-2020 Ingo Schwarze <schwarze@openbsd.org>
43 #define CHKARGS struct roff_man *man, struct roff_node *n
66 static const v_check man_valids[MAN_MAX - MAN_TH] = {
107 /* Validate the subtree rooted at man->last. */
111 struct roff_node *n; in man_validate() local
119 n = man->last; in man_validate()
120 switch (n->tok) { in man_validate()
123 n->tok = MAN_PP; in man_validate()
131 * in turn, depth-first. in man_validate()
134 man->last = man->last->child; in man_validate()
135 while (man->last != NULL) { in man_validate()
137 if (man->last == n) in man_validate()
138 man->last = man->last->child; in man_validate()
140 man->last = man->last->next; in man_validate()
145 man->last = n; in man_validate()
146 man->next = ROFF_NEXT_SIBLING; in man_validate()
147 switch (n->type) { in man_validate()
149 check_text(man, n); in man_validate()
152 check_root(man, n); in man_validate()
159 if (n->tok < ROFF_MAX) { in man_validate()
163 assert(n->tok >= MAN_TH && n->tok < MAN_MAX); in man_validate()
164 cp = man_valids + (n->tok - MAN_TH); in man_validate()
166 (*cp)(man, n); in man_validate()
167 if (man->last == n) in man_validate()
168 n->flags |= NODE_VALID; in man_validate()
176 assert((man->flags & (MAN_BLINE | MAN_ELINE)) == 0); in check_root()
178 if (n->last == NULL || n->last->type == ROFFT_COMMENT) in check_root()
179 mandoc_msg(MANDOCERR_DOC_EMPTY, n->line, n->pos, NULL); in check_root()
181 man->meta.hasbody = 1; in check_root()
183 if (NULL == man->meta.title) { in check_root()
184 mandoc_msg(MANDOCERR_TH_NOTITLE, n->line, n->pos, NULL); in check_root()
191 man->meta.title = mandoc_strdup(""); in check_root()
192 man->meta.msec = mandoc_strdup(""); in check_root()
193 man->meta.date = mandoc_normdate(NULL, NULL); in check_root()
196 if (man->meta.os_e && in check_root()
197 (man->meta.rcsids & (1 << man->meta.os_e)) == 0) in check_root()
199 man->meta.os_e == MANDOC_OS_OPENBSD ? in check_root()
215 check_tag(struct roff_node *n, struct roff_node *nt) in check_tag() argument
220 if (nt == NULL || nt->type != ROFFT_TEXT) in check_tag()
223 cp = nt->string; in check_tag()
231 case '-': in check_tag()
252 case '-': in check_tag()
265 tag_put(cp, prio, n); in check_tag()
276 if (n->flags & NODE_NOFILL) in check_text()
279 cp = n->string; in check_text()
282 n->line, n->pos + (int)(p - cp), NULL); in check_text()
288 if ((n->flags & NODE_NOFILL) == 0) in post_EE()
289 mandoc_msg(MANDOCERR_FI_SKIP, n->line, n->pos, "EE"); in post_EE()
295 if (n->flags & NODE_NOFILL) in post_EX()
296 mandoc_msg(MANDOCERR_NF_SKIP, n->line, n->pos, "EX"); in post_EX()
303 if (n->child == NULL) in post_OP()
304 mandoc_msg(MANDOCERR_OP_EMPTY, n->line, n->pos, "OP"); in post_OP()
305 else if (n->child->next != NULL && n->child->next->next != NULL) { in post_OP()
306 n = n->child->next->next; in post_OP()
308 n->line, n->pos, "OP ... %s", n->string); in post_OP()
318 nc = n->child; in post_SH()
319 switch (n->type) { in post_SH()
322 deroff(&tag, n); in post_SH()
327 if (nc != NULL && nc->type == ROFFT_TEXT && in post_SH()
328 strcmp(nc->string, tag) == 0) in post_SH()
329 tag_put(NULL, TAG_STRONG, n); in post_SH()
331 tag_put(tag, TAG_FALLBACK, n); in post_SH()
343 if (nc->tok == MAN_PP && nc->body->child != NULL) { in post_SH()
344 while (nc->body->last != NULL) { in post_SH()
345 man->next = ROFF_NEXT_CHILD; in post_SH()
346 roff_node_relink(man, nc->body->last); in post_SH()
347 man->last = n; in post_SH()
351 if (nc->tok == MAN_PP || nc->tok == ROFF_sp || nc->tok == ROFF_br) { in post_SH()
352 mandoc_msg(MANDOCERR_PAR_SKIP, nc->line, nc->pos, in post_SH()
353 "%s after %s", roff_name[nc->tok], roff_name[n->tok]); in post_SH()
362 if ((nc = n->last) != NULL && nc->tok == ROFF_br) { in post_SH()
364 nc->line, nc->pos, "%s at the end of %s", in post_SH()
365 roff_name[nc->tok], roff_name[n->tok]); in post_SH()
373 if (n->type == ROFFT_HEAD && n->child == NULL) in post_UR()
374 mandoc_msg(MANDOCERR_UR_NOHEAD, n->line, n->pos, in post_UR()
375 "%s", roff_name[n->tok]); in post_UR()
376 check_part(man, n); in post_UR()
383 if (n->type == ROFFT_BODY && n->child == NULL) in check_part()
384 mandoc_msg(MANDOCERR_BLK_EMPTY, n->line, n->pos, in check_part()
385 "%s", roff_name[n->tok]); in check_part()
392 switch (n->type) { in check_par()
394 if (n->body->child == NULL) in check_par()
395 roff_node_delete(man, n); in check_par()
398 if (n->child != NULL && in check_par()
399 (n->child->tok == ROFF_sp || n->child->tok == ROFF_br)) { in check_par()
401 n->child->line, n->child->pos, in check_par()
402 "%s after %s", roff_name[n->child->tok], in check_par()
403 roff_name[n->tok]); in check_par()
404 roff_node_delete(man, n->child); in check_par()
406 if (n->child == NULL) in check_par()
407 mandoc_msg(MANDOCERR_PAR_SKIP, n->line, n->pos, in check_par()
408 "%s empty", roff_name[n->tok]); in check_par()
411 if (n->child != NULL) in check_par()
413 n->line, n->pos, "%s %s%s", in check_par()
414 roff_name[n->tok], n->child->string, in check_par()
415 n->child->next != NULL ? " ..." : ""); in check_par()
425 switch (n->type) { in post_IP()
427 if (n->head->child == NULL && n->body->child == NULL) in post_IP()
428 roff_node_delete(man, n); in post_IP()
431 check_tag(n, n->child); in post_IP()
434 if (n->parent->head->child == NULL && n->child == NULL) in post_IP()
435 mandoc_msg(MANDOCERR_PAR_SKIP, n->line, n->pos, in post_IP()
436 "%s empty", roff_name[n->tok]); in post_IP()
444 * The first next-line element in the head is the tag.
452 if (n->type != ROFFT_HEAD || (nt = n->child) == NULL) in post_TP()
455 while ((nt->flags & NODE_LINE) == 0) in post_TP()
456 if ((nt = nt->next) == NULL) in post_TP()
459 switch (nt->tok) { in post_TP()
466 nt = nt->child; in post_TP()
471 check_tag(n, nt); in post_TP()
480 free(man->meta.title); in post_TH()
481 free(man->meta.vol); in post_TH()
482 free(man->meta.os); in post_TH()
483 free(man->meta.msec); in post_TH()
484 free(man->meta.date); in post_TH()
486 man->meta.title = man->meta.vol = man->meta.date = in post_TH()
487 man->meta.msec = man->meta.os = NULL; in post_TH()
489 nb = n; in post_TH()
491 /* ->TITLE<- MSEC DATE OS VOL */ in post_TH()
493 n = n->child; in post_TH()
494 if (n != NULL && n->string != NULL) { in post_TH()
495 for (p = n->string; *p != '\0'; p++) { in post_TH()
499 mandoc_msg(MANDOCERR_TITLE_CASE, n->line, in post_TH()
500 n->pos + (int)(p - n->string), in post_TH()
501 "TH %s", n->string); in post_TH()
505 man->meta.title = mandoc_strdup(n->string); in post_TH()
507 man->meta.title = mandoc_strdup(""); in post_TH()
508 mandoc_msg(MANDOCERR_TH_NOTITLE, nb->line, nb->pos, "TH"); in post_TH()
511 /* TITLE ->MSEC<- DATE OS VOL */ in post_TH()
513 if (n != NULL) in post_TH()
514 n = n->next; in post_TH()
515 if (n != NULL && n->string != NULL) { in post_TH()
516 man->meta.msec = mandoc_strdup(n->string); in post_TH()
517 if (man->filesec != '\0' && in post_TH()
518 man->filesec != *n->string && in post_TH()
519 *n->string >= '1' && *n->string <= '9') in post_TH()
520 mandoc_msg(MANDOCERR_MSEC_FILE, n->line, n->pos, in post_TH()
521 "*.%c vs TH ... %c", man->filesec, *n->string); in post_TH()
523 man->meta.msec = mandoc_strdup(""); in post_TH()
525 nb->line, nb->pos, "TH %s", man->meta.title); in post_TH()
528 /* TITLE MSEC ->DATE<- OS VOL */ in post_TH()
530 if (n != NULL) in post_TH()
531 n = n->next; in post_TH()
532 if (man->quick && n != NULL) in post_TH()
533 man->meta.date = mandoc_strdup(""); in post_TH()
535 man->meta.date = mandoc_normdate(n, nb); in post_TH()
537 /* TITLE MSEC DATE ->OS<- VOL */ in post_TH()
539 if (n && (n = n->next)) in post_TH()
540 man->meta.os = mandoc_strdup(n->string); in post_TH()
541 else if (man->os_s != NULL) in post_TH()
542 man->meta.os = mandoc_strdup(man->os_s); in post_TH()
543 if (man->meta.os_e == MANDOC_OS_OTHER && man->meta.os != NULL) { in post_TH()
544 if (strstr(man->meta.os, "OpenBSD") != NULL) in post_TH()
545 man->meta.os_e = MANDOC_OS_OPENBSD; in post_TH()
546 else if (strstr(man->meta.os, "NetBSD") != NULL) in post_TH()
547 man->meta.os_e = MANDOC_OS_NETBSD; in post_TH()
550 /* TITLE MSEC DATE OS ->VOL<- */ in post_TH()
553 if (n && (n = n->next)) in post_TH()
554 man->meta.vol = mandoc_strdup(n->string); in post_TH()
555 else if ('\0' != man->meta.msec[0] && in post_TH()
556 (NULL != (p = mandoc_a2msec(man->meta.msec)))) in post_TH()
557 man->meta.vol = mandoc_strdup(p); in post_TH()
559 if (n != NULL && (n = n->next) != NULL) in post_TH()
561 n->line, n->pos, "TH ... %s", n->string); in post_TH()
565 * meta-data. in post_TH()
567 roff_node_delete(man, man->last); in post_TH()
583 n = n->child; in post_UC()
585 if (n == NULL || n->type != ROFFT_TEXT) in post_UC()
588 s = n->string; in post_UC()
603 free(man->meta.os); in post_UC()
604 man->meta.os = mandoc_strdup(p); in post_UC()
620 n = n->child; in post_AT()
622 if (n == NULL || n->type != ROFFT_TEXT) in post_AT()
625 s = n->string; in post_AT()
631 nn = n->next; in post_AT()
633 nn->type == ROFFT_TEXT && in post_AT()
634 nn->string[0] != '\0') in post_AT()
642 free(man->meta.os); in post_AT()
643 man->meta.os = mandoc_strdup(p); in post_AT()
651 if (n->parent->tok != MAN_TP || in post_in()
652 n->parent->type != ROFFT_HEAD || in post_in()
653 n->child == NULL || in post_in()
654 *n->child->string == '+' || in post_in()
655 *n->child->string == '-') in post_in()
657 mandoc_asprintf(&s, "+%s", n->child->string); in post_in()
658 free(n->child->string); in post_in()
659 n->child->string = s; in post_in()