Lines Matching +full:- +full:n

3  * Copyright (c) 2010, 2012-2020, 2023 Ingo Schwarze <schwarze@openbsd.org>
44 #define CHKARGS struct roff_man *man, struct roff_node *n
67 static const v_check man_valids[MAN_MAX - MAN_TH] = {
109 /* Validate the subtree rooted at man->last. */
113 struct roff_node *n; in man_validate() local
118 * in turn, depth-first. in man_validate()
121 n = man->last; in man_validate()
122 man->last = man->last->child; in man_validate()
123 while (man->last != NULL) { in man_validate()
125 if (man->last == n) in man_validate()
126 man->last = man->last->child; in man_validate()
128 man->last = man->last->next; in man_validate()
133 man->last = n; in man_validate()
134 man->next = ROFF_NEXT_SIBLING; in man_validate()
135 switch (n->type) { in man_validate()
137 check_text(man, n); in man_validate()
140 check_root(man, n); in man_validate()
147 if (n->tok < ROFF_MAX) { in man_validate()
151 assert(n->tok >= MAN_TH && n->tok < MAN_MAX); in man_validate()
152 cp = man_valids + (n->tok - MAN_TH); in man_validate()
154 (*cp)(man, n); in man_validate()
155 if (man->last == n) in man_validate()
156 n->flags |= NODE_VALID; in man_validate()
164 assert((man->flags & (MAN_BLINE | MAN_ELINE)) == 0); in check_root()
166 if (n->last == NULL || n->last->type == ROFFT_COMMENT) in check_root()
167 mandoc_msg(MANDOCERR_DOC_EMPTY, n->line, n->pos, NULL); in check_root()
169 man->meta.hasbody = 1; in check_root()
171 if (NULL == man->meta.title) { in check_root()
172 mandoc_msg(MANDOCERR_TH_NOTITLE, n->line, n->pos, NULL); in check_root()
179 man->meta.title = mandoc_strdup(""); in check_root()
180 man->meta.msec = mandoc_strdup(""); in check_root()
181 man->meta.date = mandoc_normdate(NULL, NULL); in check_root()
184 if (man->meta.os_e && in check_root()
185 (man->meta.rcsids & (1 << man->meta.os_e)) == 0) in check_root()
187 man->meta.os_e == MANDOC_OS_OPENBSD ? in check_root()
197 check_tag(struct roff_node *n, struct roff_node *nt) in check_tag() argument
202 if (nt == NULL || nt->type != ROFFT_TEXT) in check_tag()
205 cp = nt->string; in check_tag()
213 case '-': in check_tag()
234 case '-': in check_tag()
247 tag_put(cp, prio, n); in check_tag()
258 if (n->flags & NODE_NOFILL) in check_text()
261 cp = n->string; in check_text()
264 n->line, n->pos + (int)(p - cp), NULL); in check_text()
270 if ((n->flags & NODE_NOFILL) == 0) in post_EE()
271 mandoc_msg(MANDOCERR_FI_SKIP, n->line, n->pos, "EE"); in post_EE()
277 if (n->flags & NODE_NOFILL) in post_EX()
278 mandoc_msg(MANDOCERR_NF_SKIP, n->line, n->pos, "EX"); in post_EX()
285 if (n->child == NULL) in post_OP()
286 mandoc_msg(MANDOCERR_OP_EMPTY, n->line, n->pos, "OP"); in post_OP()
287 else if (n->child->next != NULL && n->child->next->next != NULL) { in post_OP()
288 n = n->child->next->next; in post_OP()
290 n->line, n->pos, "OP ... %s", n->string); in post_OP()
300 nc = n->child; in post_SH()
301 switch (n->type) { in post_SH()
304 deroff(&tag, n); in post_SH()
309 if (nc != NULL && nc->type == ROFFT_TEXT && in post_SH()
310 strcmp(nc->string, tag) == 0) in post_SH()
311 tag_put(NULL, TAG_STRONG, n); in post_SH()
313 tag_put(tag, TAG_FALLBACK, n); in post_SH()
325 if ((nc->tok == MAN_LP || nc->tok == MAN_PP || nc->tok == MAN_P) && in post_SH()
326 nc->body->child != NULL) { in post_SH()
327 while (nc->body->last != NULL) { in post_SH()
328 man->next = ROFF_NEXT_CHILD; in post_SH()
329 roff_node_relink(man, nc->body->last); in post_SH()
330 man->last = n; in post_SH()
334 if (nc->tok == MAN_LP || nc->tok == MAN_PP || nc->tok == MAN_P || in post_SH()
335 nc->tok == ROFF_sp || nc->tok == ROFF_br) { in post_SH()
336 mandoc_msg(MANDOCERR_PAR_SKIP, nc->line, nc->pos, in post_SH()
337 "%s after %s", roff_name[nc->tok], roff_name[n->tok]); in post_SH()
346 if ((nc = n->last) != NULL && nc->tok == ROFF_br) { in post_SH()
348 nc->line, nc->pos, "%s at the end of %s", in post_SH()
349 roff_name[nc->tok], roff_name[n->tok]); in post_SH()
357 if (n->type == ROFFT_HEAD && n->child == NULL) in post_UR()
358 mandoc_msg(MANDOCERR_UR_NOHEAD, n->line, n->pos, in post_UR()
359 "%s", roff_name[n->tok]); in post_UR()
365 if (n->type == ROFFT_BODY && n->child == NULL) in check_part()
366 mandoc_msg(MANDOCERR_BLK_EMPTY, n->line, n->pos, in check_part()
367 "%s", roff_name[n->tok]); in check_part()
374 switch (n->type) { in check_par()
376 if (n->body->child == NULL) in check_par()
377 roff_node_delete(man, n); in check_par()
380 if (n->child != NULL && in check_par()
381 (n->child->tok == ROFF_sp || n->child->tok == ROFF_br)) { in check_par()
383 n->child->line, n->child->pos, in check_par()
384 "%s after %s", roff_name[n->child->tok], in check_par()
385 roff_name[n->tok]); in check_par()
386 roff_node_delete(man, n->child); in check_par()
388 if (n->child == NULL) in check_par()
389 mandoc_msg(MANDOCERR_PAR_SKIP, n->line, n->pos, in check_par()
390 "%s empty", roff_name[n->tok]); in check_par()
393 if (n->child != NULL) in check_par()
395 n->line, n->pos, "%s %s%s", in check_par()
396 roff_name[n->tok], n->child->string, in check_par()
397 n->child->next != NULL ? " ..." : ""); in check_par()
407 switch (n->type) { in post_IP()
409 if (n->head->child == NULL && n->body->child == NULL) in post_IP()
410 roff_node_delete(man, n); in post_IP()
413 check_tag(n, n->child); in post_IP()
416 if (n->parent->head->child == NULL && n->child == NULL) in post_IP()
417 mandoc_msg(MANDOCERR_PAR_SKIP, n->line, n->pos, in post_IP()
418 "%s empty", roff_name[n->tok]); in post_IP()
426 * The first next-line element in the head is the tag.
434 if (n->type != ROFFT_HEAD || (nt = n->child) == NULL) in post_TP()
437 while ((nt->flags & NODE_LINE) == 0) in post_TP()
438 if ((nt = nt->next) == NULL) in post_TP()
441 switch (nt->tok) { in post_TP()
448 nt = nt->child; in post_TP()
453 check_tag(n, nt); in post_TP()
462 free(man->meta.title); in post_TH()
463 free(man->meta.vol); in post_TH()
464 free(man->meta.os); in post_TH()
465 free(man->meta.msec); in post_TH()
466 free(man->meta.date); in post_TH()
468 man->meta.title = man->meta.vol = man->meta.date = in post_TH()
469 man->meta.msec = man->meta.os = NULL; in post_TH()
471 nb = n; in post_TH()
473 /* ->TITLE<- MSEC DATE OS VOL */ in post_TH()
475 n = n->child; in post_TH()
476 if (n != NULL && n->string != NULL) { in post_TH()
477 for (p = n->string; *p != '\0'; p++) { in post_TH()
481 mandoc_msg(MANDOCERR_TITLE_CASE, n->line, in post_TH()
482 n->pos + (int)(p - n->string), in post_TH()
483 "TH %s", n->string); in post_TH()
487 man->meta.title = mandoc_strdup(n->string); in post_TH()
489 man->meta.title = mandoc_strdup(""); in post_TH()
490 mandoc_msg(MANDOCERR_TH_NOTITLE, nb->line, nb->pos, "TH"); in post_TH()
493 /* TITLE ->MSEC<- DATE OS VOL */ in post_TH()
495 if (n != NULL) in post_TH()
496 n = n->next; in post_TH()
497 if (n != NULL && n->string != NULL) { in post_TH()
498 man->meta.msec = mandoc_strdup(n->string); in post_TH()
499 if (man->filesec != '\0' && in post_TH()
500 man->filesec != *n->string && in post_TH()
501 *n->string >= '1' && *n->string <= '9') in post_TH()
502 mandoc_msg(MANDOCERR_MSEC_FILE, n->line, n->pos, in post_TH()
503 "*.%c vs TH ... %c", man->filesec, *n->string); in post_TH()
505 man->meta.msec = mandoc_strdup(""); in post_TH()
507 nb->line, nb->pos, "TH %s", man->meta.title); in post_TH()
510 /* TITLE MSEC ->DATE<- OS VOL */ in post_TH()
512 if (n != NULL) in post_TH()
513 n = n->next; in post_TH()
514 if (man->quick && n != NULL) in post_TH()
515 man->meta.date = mandoc_strdup(""); in post_TH()
517 man->meta.date = mandoc_normdate(n, nb); in post_TH()
519 /* TITLE MSEC DATE ->OS<- VOL */ in post_TH()
521 if (n && (n = n->next)) in post_TH()
522 man->meta.os = mandoc_strdup(n->string); in post_TH()
523 else if (man->os_s != NULL) in post_TH()
524 man->meta.os = mandoc_strdup(man->os_s); in post_TH()
525 if (man->meta.os_e == MANDOC_OS_OTHER && man->meta.os != NULL) { in post_TH()
526 if (strstr(man->meta.os, "OpenBSD") != NULL) in post_TH()
527 man->meta.os_e = MANDOC_OS_OPENBSD; in post_TH()
528 else if (strstr(man->meta.os, "NetBSD") != NULL) in post_TH()
529 man->meta.os_e = MANDOC_OS_NETBSD; in post_TH()
532 /* TITLE MSEC DATE OS ->VOL<- */ in post_TH()
535 if (n && (n = n->next)) in post_TH()
536 man->meta.vol = mandoc_strdup(n->string); in post_TH()
537 else if ('\0' != man->meta.msec[0] && in post_TH()
538 (NULL != (p = mandoc_a2msec(man->meta.msec)))) in post_TH()
539 man->meta.vol = mandoc_strdup(p); in post_TH()
541 if (n != NULL && (n = n->next) != NULL) in post_TH()
543 n->line, n->pos, "TH ... %s", n->string); in post_TH()
547 * meta-data. in post_TH()
549 roff_node_delete(man, man->last); in post_TH()
557 if ((nch = n->child) == NULL) { in post_MR()
558 mandoc_msg(MANDOCERR_NM_NONAME, n->line, n->pos, "MR"); in post_MR()
561 if (nch->next == NULL) { in post_MR()
563 n->line, n->pos, "MR %s", nch->string); in post_MR()
566 if (mandoc_xr_add(nch->next->string, nch->string, nch->line, nch->pos)) in post_MR()
567 mandoc_msg(MANDOCERR_XR_SELF, nch->line, nch->pos, in post_MR()
568 "MR %s %s", nch->string, nch->next->string); in post_MR()
569 if ((nch = nch->next->next) == NULL || nch->next == NULL) in post_MR()
572 mandoc_msg(MANDOCERR_ARG_EXCESS, nch->next->line, nch->next->pos, in post_MR()
573 "MR ... %s", nch->next->string); in post_MR()
574 while (nch->next != NULL) in post_MR()
575 roff_node_delete(man, nch->next); in post_MR()
591 n = n->child; in post_UC()
593 if (n == NULL || n->type != ROFFT_TEXT) in post_UC()
596 s = n->string; in post_UC()
611 free(man->meta.os); in post_UC()
612 man->meta.os = mandoc_strdup(p); in post_UC()
628 n = n->child; in post_AT()
630 if (n == NULL || n->type != ROFFT_TEXT) in post_AT()
633 s = n->string; in post_AT()
639 nn = n->next; in post_AT()
641 nn->type == ROFFT_TEXT && in post_AT()
642 nn->string[0] != '\0') in post_AT()
650 free(man->meta.os); in post_AT()
651 man->meta.os = mandoc_strdup(p); in post_AT()
659 if (n->parent->tok != MAN_TP || in post_in()
660 n->parent->type != ROFFT_HEAD || in post_in()
661 n->child == NULL || in post_in()
662 *n->child->string == '+' || in post_in()
663 *n->child->string == '-') in post_in()
665 mandoc_asprintf(&s, "+%s", n->child->string); in post_in()
666 free(n->child->string); in post_in()
667 n->child->string = s; in post_in()