mdoc_validate.c (fa072f7f) | mdoc_validate.c (d1982c71) |
---|---|
1/* $OpenBSD: mdoc_validate.c,v 1.199 2015/02/23 13:54:39 schwarze Exp $ */ | 1/* $OpenBSD: mdoc_validate.c,v 1.200 2015/04/02 21:03:18 schwarze Exp $ */ |
2/* 3 * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv> 4 * Copyright (c) 2010-2015 Ingo Schwarze <schwarze@openbsd.org> 5 * Copyright (c) 2010 Joerg Sonnenberger <joerg@netbsd.org> 6 * 7 * Permission to use, copy, modify, and distribute this software for any 8 * purpose with or without fee is hereby granted, provided that the above 9 * copyright notice and this permission notice appear in all copies. 10 * | 2/* 3 * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv> 4 * Copyright (c) 2010-2015 Ingo Schwarze <schwarze@openbsd.org> 5 * Copyright (c) 2010 Joerg Sonnenberger <joerg@netbsd.org> 6 * 7 * Permission to use, copy, modify, and distribute this software for any 8 * purpose with or without fee is hereby granted, provided that the above 9 * copyright notice and this permission notice appear in all copies. 10 * |
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | 11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES |
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | 12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | 13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR |
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18 */ 19#include <sys/types.h> 20#ifndef OSNAME 21#include <sys/utsname.h> 22#endif 23 24#include <assert.h> 25#include <ctype.h> 26#include <limits.h> 27#include <stdio.h> 28#include <stdlib.h> 29#include <string.h> 30#include <time.h> 31 | 14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18 */ 19#include <sys/types.h> 20#ifndef OSNAME 21#include <sys/utsname.h> 22#endif 23 24#include <assert.h> 25#include <ctype.h> 26#include <limits.h> 27#include <stdio.h> 28#include <stdlib.h> 29#include <string.h> 30#include <time.h> 31 |
32#include "mdoc.h" 33#include "mandoc.h" | |
34#include "mandoc_aux.h" | 32#include "mandoc_aux.h" |
35#include "libmdoc.h" | 33#include "mandoc.h" 34#include "roff.h" 35#include "mdoc.h" |
36#include "libmandoc.h" | 36#include "libmandoc.h" |
37#include "libmdoc.h" |
|
37 38/* FIXME: .Bl -diag can't have non-text children in HEAD. */ 39 40#define PRE_ARGS struct mdoc *mdoc, struct mdoc_node *n 41#define POST_ARGS struct mdoc *mdoc 42 43enum check_ineq { 44 CHECK_LT, --- 245 unchanged lines hidden (view full) --- 290 291 292void 293mdoc_valid_pre(struct mdoc *mdoc, struct mdoc_node *n) 294{ 295 v_pre p; 296 297 switch (n->type) { | 38 39/* FIXME: .Bl -diag can't have non-text children in HEAD. */ 40 41#define PRE_ARGS struct mdoc *mdoc, struct mdoc_node *n 42#define POST_ARGS struct mdoc *mdoc 43 44enum check_ineq { 45 CHECK_LT, --- 245 unchanged lines hidden (view full) --- 291 292 293void 294mdoc_valid_pre(struct mdoc *mdoc, struct mdoc_node *n) 295{ 296 v_pre p; 297 298 switch (n->type) { |
298 case MDOC_TEXT: | 299 case ROFFT_TEXT: |
299 if (n->sec != SEC_SYNOPSIS || n->parent->tok != MDOC_Fd) 300 check_text(mdoc, n->line, n->pos, n->string); 301 /* FALLTHROUGH */ | 300 if (n->sec != SEC_SYNOPSIS || n->parent->tok != MDOC_Fd) 301 check_text(mdoc, n->line, n->pos, n->string); 302 /* FALLTHROUGH */ |
302 case MDOC_TBL: | 303 case ROFFT_TBL: |
303 /* FALLTHROUGH */ | 304 /* FALLTHROUGH */ |
304 case MDOC_EQN: | 305 case ROFFT_EQN: |
305 /* FALLTHROUGH */ | 306 /* FALLTHROUGH */ |
306 case MDOC_ROOT: | 307 case ROFFT_ROOT: |
307 return; 308 default: 309 break; 310 } 311 312 check_args(mdoc, n); 313 p = mdoc_valids[n->tok].pre; 314 if (*p) --- 7 unchanged lines hidden (view full) --- 322 v_post p; 323 324 n = mdoc->last; 325 if (n->flags & MDOC_VALID) 326 return; 327 n->flags |= MDOC_VALID | MDOC_ENDED; 328 329 switch (n->type) { | 308 return; 309 default: 310 break; 311 } 312 313 check_args(mdoc, n); 314 p = mdoc_valids[n->tok].pre; 315 if (*p) --- 7 unchanged lines hidden (view full) --- 323 v_post p; 324 325 n = mdoc->last; 326 if (n->flags & MDOC_VALID) 327 return; 328 n->flags |= MDOC_VALID | MDOC_ENDED; 329 330 switch (n->type) { |
330 case MDOC_TEXT: | 331 case ROFFT_TEXT: |
331 /* FALLTHROUGH */ | 332 /* FALLTHROUGH */ |
332 case MDOC_EQN: | 333 case ROFFT_EQN: |
333 /* FALLTHROUGH */ | 334 /* FALLTHROUGH */ |
334 case MDOC_TBL: | 335 case ROFFT_TBL: |
335 break; | 336 break; |
336 case MDOC_ROOT: | 337 case ROFFT_ROOT: |
337 post_root(mdoc); 338 break; 339 default: 340 341 /* 342 * Closing delimiters are not special at the 343 * beginning of a block, opening delimiters 344 * are not special at the end. --- 48 unchanged lines hidden (view full) --- 393 ln, pos + (int)(p - cp), NULL); 394} 395 396static void 397pre_display(PRE_ARGS) 398{ 399 struct mdoc_node *node; 400 | 338 post_root(mdoc); 339 break; 340 default: 341 342 /* 343 * Closing delimiters are not special at the 344 * beginning of a block, opening delimiters 345 * are not special at the end. --- 48 unchanged lines hidden (view full) --- 394 ln, pos + (int)(p - cp), NULL); 395} 396 397static void 398pre_display(PRE_ARGS) 399{ 400 struct mdoc_node *node; 401 |
401 if (MDOC_BLOCK != n->type) | 402 if (n->type != ROFFT_BLOCK) |
402 return; 403 404 for (node = mdoc->last->parent; node; node = node->parent) | 403 return; 404 405 for (node = mdoc->last->parent; node; node = node->parent) |
405 if (MDOC_BLOCK == node->type) | 406 if (node->type == ROFFT_BLOCK) |
406 if (MDOC_Bd == node->tok) 407 break; 408 409 if (node) 410 mandoc_vmsg(MANDOCERR_BD_NEST, 411 mdoc->parse, n->line, n->pos, 412 "%s in Bd", mdoc_macronames[n->tok]); 413} 414 415static void 416pre_bl(PRE_ARGS) 417{ 418 struct mdoc_argv *argv, *wa; 419 int i; 420 enum mdocargt mdoclt; 421 enum mdoc_list lt; 422 | 407 if (MDOC_Bd == node->tok) 408 break; 409 410 if (node) 411 mandoc_vmsg(MANDOCERR_BD_NEST, 412 mdoc->parse, n->line, n->pos, 413 "%s in Bd", mdoc_macronames[n->tok]); 414} 415 416static void 417pre_bl(PRE_ARGS) 418{ 419 struct mdoc_argv *argv, *wa; 420 int i; 421 enum mdocargt mdoclt; 422 enum mdoc_list lt; 423 |
423 if (n->type != MDOC_BLOCK) | 424 if (n->type != ROFFT_BLOCK) |
424 return; 425 426 /* 427 * First figure out which kind of list to use: bind ourselves to 428 * the first mentioned list type and warn about any remaining 429 * ones. If we find no list type, we default to LIST_item. 430 */ 431 --- 166 unchanged lines hidden (view full) --- 598pre_bd(PRE_ARGS) 599{ 600 struct mdoc_argv *argv; 601 int i; 602 enum mdoc_disp dt; 603 604 pre_literal(mdoc, n); 605 | 425 return; 426 427 /* 428 * First figure out which kind of list to use: bind ourselves to 429 * the first mentioned list type and warn about any remaining 430 * ones. If we find no list type, we default to LIST_item. 431 */ 432 --- 166 unchanged lines hidden (view full) --- 599pre_bd(PRE_ARGS) 600{ 601 struct mdoc_argv *argv; 602 int i; 603 enum mdoc_disp dt; 604 605 pre_literal(mdoc, n); 606 |
606 if (n->type != MDOC_BLOCK) | 607 if (n->type != ROFFT_BLOCK) |
607 return; 608 609 for (i = 0; n->args && i < (int)n->args->argc; i++) { 610 argv = n->args->argv + i; 611 dt = DISP__NONE; 612 613 switch (argv->arg) { 614 case MDOC_Centred: --- 96 unchanged lines hidden (view full) --- 711 mandoc_msg(MANDOCERR_ARG_STD, mdoc->parse, 712 n->line, n->pos, mdoc_macronames[n->tok]); 713} 714 715static void 716pre_obsolete(PRE_ARGS) 717{ 718 | 608 return; 609 610 for (i = 0; n->args && i < (int)n->args->argc; i++) { 611 argv = n->args->argv + i; 612 dt = DISP__NONE; 613 614 switch (argv->arg) { 615 case MDOC_Centred: --- 96 unchanged lines hidden (view full) --- 712 mandoc_msg(MANDOCERR_ARG_STD, mdoc->parse, 713 n->line, n->pos, mdoc_macronames[n->tok]); 714} 715 716static void 717pre_obsolete(PRE_ARGS) 718{ 719 |
719 if (MDOC_ELEM == n->type || MDOC_BLOCK == n->type) | 720 if (n->type == ROFFT_ELEM || n->type == ROFFT_BLOCK) |
720 mandoc_msg(MANDOCERR_MACRO_OBS, mdoc->parse, 721 n->line, n->pos, mdoc_macronames[n->tok]); 722} 723 724static void 725pre_dt(PRE_ARGS) 726{ 727 --- 42 unchanged lines hidden (view full) --- 770 enum mdocargt arg; 771 772 /* 773 * Unlike other data pointers, these are "housed" by the HEAD 774 * element, which contains the goods. 775 */ 776 777 np = mdoc->last; | 721 mandoc_msg(MANDOCERR_MACRO_OBS, mdoc->parse, 722 n->line, n->pos, mdoc_macronames[n->tok]); 723} 724 725static void 726pre_dt(PRE_ARGS) 727{ 728 --- 42 unchanged lines hidden (view full) --- 771 enum mdocargt arg; 772 773 /* 774 * Unlike other data pointers, these are "housed" by the HEAD 775 * element, which contains the goods. 776 */ 777 778 np = mdoc->last; |
778 if (MDOC_HEAD != np->type) | 779 if (np->type != ROFFT_HEAD) |
779 return; 780 | 780 return; 781 |
781 assert(MDOC_BLOCK == np->parent->type); | 782 assert(np->parent->type == ROFFT_BLOCK); |
782 assert(MDOC_Bf == np->parent->tok); 783 784 /* Check the number of arguments. */ 785 786 nch = np->child; 787 if (NULL == np->parent->args) { 788 if (NULL == nch) { 789 mandoc_msg(MANDOCERR_BF_NOFONT, mdoc->parse, --- 37 unchanged lines hidden (view full) --- 827 828static void 829post_lb(POST_ARGS) 830{ 831 struct mdoc_node *n; 832 char *libname; 833 834 n = mdoc->last->child; | 783 assert(MDOC_Bf == np->parent->tok); 784 785 /* Check the number of arguments. */ 786 787 nch = np->child; 788 if (NULL == np->parent->args) { 789 if (NULL == nch) { 790 mandoc_msg(MANDOCERR_BF_NOFONT, mdoc->parse, --- 37 unchanged lines hidden (view full) --- 828 829static void 830post_lb(POST_ARGS) 831{ 832 struct mdoc_node *n; 833 char *libname; 834 835 n = mdoc->last->child; |
835 assert(MDOC_TEXT == n->type); | 836 assert(n->type == ROFFT_TEXT); |
836 mandoc_asprintf(&libname, "library \\(Lq%s\\(Rq", n->string); 837 free(n->string); 838 n->string = libname; 839} 840 841static void 842post_eoln(POST_ARGS) 843{ --- 32 unchanged lines hidden (view full) --- 876 877static void 878post_fo(POST_ARGS) 879{ 880 const struct mdoc_node *n; 881 882 n = mdoc->last; 883 | 837 mandoc_asprintf(&libname, "library \\(Lq%s\\(Rq", n->string); 838 free(n->string); 839 n->string = libname; 840} 841 842static void 843post_eoln(POST_ARGS) 844{ --- 32 unchanged lines hidden (view full) --- 877 878static void 879post_fo(POST_ARGS) 880{ 881 const struct mdoc_node *n; 882 883 n = mdoc->last; 884 |
884 if (n->type != MDOC_HEAD) | 885 if (n->type != ROFFT_HEAD) |
885 return; 886 887 if (n->child == NULL) { 888 mandoc_msg(MANDOCERR_FO_NOHEAD, mdoc->parse, 889 n->line, n->pos, "Fo"); 890 return; 891 } 892 if (n->child != n->last) { --- 36 unchanged lines hidden (view full) --- 929 /* 930 * The Vt macro comes in both ELEM and BLOCK form, both of which 931 * have different syntaxes (yet more context-sensitive 932 * behaviour). ELEM types must have a child, which is already 933 * guaranteed by the in_line parsing routine; BLOCK types, 934 * specifically the BODY, should only have TEXT children. 935 */ 936 | 886 return; 887 888 if (n->child == NULL) { 889 mandoc_msg(MANDOCERR_FO_NOHEAD, mdoc->parse, 890 n->line, n->pos, "Fo"); 891 return; 892 } 893 if (n->child != n->last) { --- 36 unchanged lines hidden (view full) --- 930 /* 931 * The Vt macro comes in both ELEM and BLOCK form, both of which 932 * have different syntaxes (yet more context-sensitive 933 * behaviour). ELEM types must have a child, which is already 934 * guaranteed by the in_line parsing routine; BLOCK types, 935 * specifically the BODY, should only have TEXT children. 936 */ 937 |
937 if (MDOC_BODY != mdoc->last->type) | 938 if (mdoc->last->type != ROFFT_BODY) |
938 return; 939 940 for (n = mdoc->last->child; n; n = n->next) | 939 return; 940 941 for (n = mdoc->last->child; n; n = n->next) |
941 if (MDOC_TEXT != n->type) | 942 if (n->type != ROFFT_TEXT) |
942 mandoc_msg(MANDOCERR_VT_CHILD, mdoc->parse, 943 n->line, n->pos, mdoc_macronames[n->tok]); 944} 945 946static void 947post_nm(POST_ARGS) 948{ 949 struct mdoc_node *n; --- 17 unchanged lines hidden (view full) --- 967 968static void 969post_nd(POST_ARGS) 970{ 971 struct mdoc_node *n; 972 973 n = mdoc->last; 974 | 943 mandoc_msg(MANDOCERR_VT_CHILD, mdoc->parse, 944 n->line, n->pos, mdoc_macronames[n->tok]); 945} 946 947static void 948post_nm(POST_ARGS) 949{ 950 struct mdoc_node *n; --- 17 unchanged lines hidden (view full) --- 968 969static void 970post_nd(POST_ARGS) 971{ 972 struct mdoc_node *n; 973 974 n = mdoc->last; 975 |
975 if (n->type != MDOC_BODY) | 976 if (n->type != ROFFT_BODY) |
976 return; 977 978 if (n->child == NULL) 979 mandoc_msg(MANDOCERR_ND_EMPTY, mdoc->parse, 980 n->line, n->pos, "Nd"); 981 982 post_hyph(mdoc); 983} 984 985static void 986post_d1(POST_ARGS) 987{ 988 struct mdoc_node *n; 989 990 n = mdoc->last; 991 | 977 return; 978 979 if (n->child == NULL) 980 mandoc_msg(MANDOCERR_ND_EMPTY, mdoc->parse, 981 n->line, n->pos, "Nd"); 982 983 post_hyph(mdoc); 984} 985 986static void 987post_d1(POST_ARGS) 988{ 989 struct mdoc_node *n; 990 991 n = mdoc->last; 992 |
992 if (n->type != MDOC_BODY) | 993 if (n->type != ROFFT_BODY) |
993 return; 994 995 if (n->child == NULL) 996 mandoc_msg(MANDOCERR_BLK_EMPTY, mdoc->parse, 997 n->line, n->pos, "D1"); 998 999 post_hyph(mdoc); 1000} 1001 1002static void 1003post_literal(POST_ARGS) 1004{ 1005 struct mdoc_node *n; 1006 1007 n = mdoc->last; 1008 | 994 return; 995 996 if (n->child == NULL) 997 mandoc_msg(MANDOCERR_BLK_EMPTY, mdoc->parse, 998 n->line, n->pos, "D1"); 999 1000 post_hyph(mdoc); 1001} 1002 1003static void 1004post_literal(POST_ARGS) 1005{ 1006 struct mdoc_node *n; 1007 1008 n = mdoc->last; 1009 |
1009 if (n->type != MDOC_BODY) | 1010 if (n->type != ROFFT_BODY) |
1010 return; 1011 1012 if (n->child == NULL) 1013 mandoc_msg(MANDOCERR_BLK_EMPTY, mdoc->parse, 1014 n->line, n->pos, mdoc_macronames[n->tok]); 1015 1016 if (n->tok == MDOC_Bd && 1017 n->norm->Bd.type != DISP_literal && --- 54 unchanged lines hidden (view full) --- 1072 1073 /* 1074 * If we have a child, look it up in the standard keys. If a 1075 * key exist, use that instead of the child; if it doesn't, 1076 * prefix "AT&T UNIX " to the existing data. 1077 */ 1078 1079 n = n->child; | 1011 return; 1012 1013 if (n->child == NULL) 1014 mandoc_msg(MANDOCERR_BLK_EMPTY, mdoc->parse, 1015 n->line, n->pos, mdoc_macronames[n->tok]); 1016 1017 if (n->tok == MDOC_Bd && 1018 n->norm->Bd.type != DISP_literal && --- 54 unchanged lines hidden (view full) --- 1073 1074 /* 1075 * If we have a child, look it up in the standard keys. If a 1076 * key exist, use that instead of the child; if it doesn't, 1077 * prefix "AT&T UNIX " to the existing data. 1078 */ 1079 1080 n = n->child; |
1080 assert(MDOC_TEXT == n->type); | 1081 assert(n->type == ROFFT_TEXT); |
1081 if (NULL == (std_att = mdoc_a2att(n->string))) { 1082 mandoc_vmsg(MANDOCERR_AT_BAD, mdoc->parse, 1083 n->line, n->pos, "At %s", n->string); 1084 mandoc_asprintf(&att, "AT&T UNIX %s", n->string); 1085 } else 1086 att = mandoc_strdup(std_att); 1087 1088 free(n->string); --- 15 unchanged lines hidden (view full) --- 1104 mandoc_vmsg(MANDOCERR_ARG_EXCESS, mdoc->parse, 1105 nch->line, nch->pos, "An ... %s", nch->string); 1106} 1107 1108static void 1109post_en(POST_ARGS) 1110{ 1111 | 1082 if (NULL == (std_att = mdoc_a2att(n->string))) { 1083 mandoc_vmsg(MANDOCERR_AT_BAD, mdoc->parse, 1084 n->line, n->pos, "At %s", n->string); 1085 mandoc_asprintf(&att, "AT&T UNIX %s", n->string); 1086 } else 1087 att = mandoc_strdup(std_att); 1088 1089 free(n->string); --- 15 unchanged lines hidden (view full) --- 1105 mandoc_vmsg(MANDOCERR_ARG_EXCESS, mdoc->parse, 1106 nch->line, nch->pos, "An ... %s", nch->string); 1107} 1108 1109static void 1110post_en(POST_ARGS) 1111{ 1112 |
1112 if (MDOC_BLOCK == mdoc->last->type) | 1113 if (mdoc->last->type == ROFFT_BLOCK) |
1113 mdoc->last->norm->Es = mdoc->last_es; 1114} 1115 1116static void 1117post_es(POST_ARGS) 1118{ 1119 1120 mdoc->last_es = mdoc->last; 1121} 1122 1123static void 1124post_it(POST_ARGS) 1125{ 1126 int i, cols; 1127 enum mdoc_list lt; 1128 struct mdoc_node *nbl, *nit, *nch; 1129 1130 nit = mdoc->last; | 1114 mdoc->last->norm->Es = mdoc->last_es; 1115} 1116 1117static void 1118post_es(POST_ARGS) 1119{ 1120 1121 mdoc->last_es = mdoc->last; 1122} 1123 1124static void 1125post_it(POST_ARGS) 1126{ 1127 int i, cols; 1128 enum mdoc_list lt; 1129 struct mdoc_node *nbl, *nit, *nch; 1130 1131 nit = mdoc->last; |
1131 if (nit->type != MDOC_BLOCK) | 1132 if (nit->type != ROFFT_BLOCK) |
1132 return; 1133 1134 nbl = nit->parent->parent; 1135 lt = nbl->norm->Bl.type; 1136 1137 switch (lt) { 1138 case LIST_tag: 1139 /* FALLTHROUGH */ --- 30 unchanged lines hidden (view full) --- 1170 "It %s", nit->head->child->string); 1171 break; 1172 case LIST_column: 1173 cols = (int)nbl->norm->Bl.ncols; 1174 1175 assert(nit->head->child == NULL); 1176 1177 for (i = 0, nch = nit->child; nch; nch = nch->next) | 1133 return; 1134 1135 nbl = nit->parent->parent; 1136 lt = nbl->norm->Bl.type; 1137 1138 switch (lt) { 1139 case LIST_tag: 1140 /* FALLTHROUGH */ --- 30 unchanged lines hidden (view full) --- 1171 "It %s", nit->head->child->string); 1172 break; 1173 case LIST_column: 1174 cols = (int)nbl->norm->Bl.ncols; 1175 1176 assert(nit->head->child == NULL); 1177 1178 for (i = 0, nch = nit->child; nch; nch = nch->next) |
1178 if (nch->type == MDOC_BODY) | 1179 if (nch->type == ROFFT_BODY) |
1179 i++; 1180 1181 if (i < cols || i > cols + 1) 1182 mandoc_vmsg(MANDOCERR_BL_COL, 1183 mdoc->parse, nit->line, nit->pos, 1184 "%d columns, %d cells", cols, i); 1185 break; 1186 default: --- 97 unchanged lines hidden (view full) --- 1284 1285 sz = 10; 1286 n = mdoc->last; 1287 1288 for (nn = n->body->child; nn; nn = nn->next) { 1289 if (MDOC_It != nn->tok) 1290 continue; 1291 | 1180 i++; 1181 1182 if (i < cols || i > cols + 1) 1183 mandoc_vmsg(MANDOCERR_BL_COL, 1184 mdoc->parse, nit->line, nit->pos, 1185 "%d columns, %d cells", cols, i); 1186 break; 1187 default: --- 97 unchanged lines hidden (view full) --- 1285 1286 sz = 10; 1287 n = mdoc->last; 1288 1289 for (nn = n->body->child; nn; nn = nn->next) { 1290 if (MDOC_It != nn->tok) 1291 continue; 1292 |
1292 assert(MDOC_BLOCK == nn->type); | 1293 assert(nn->type == ROFFT_BLOCK); |
1293 nn = nn->head->child; 1294 1295 if (nn == NULL) 1296 break; 1297 | 1294 nn = nn->head->child; 1295 1296 if (nn == NULL) 1297 break; 1298 |
1298 if (MDOC_TEXT == nn->type) { | 1299 if (nn->type == ROFFT_TEXT) { |
1299 sz = strlen(nn->string) + 1; 1300 break; 1301 } 1302 1303 if (0 != (ssz = macro2len(nn->tok))) 1304 sz = ssz; 1305 1306 break; --- 91 unchanged lines hidden (view full) --- 1398post_bl(POST_ARGS) 1399{ 1400 struct mdoc_node *nparent, *nprev; /* of the Bl block */ 1401 struct mdoc_node *nblock, *nbody; /* of the Bl */ 1402 struct mdoc_node *nchild, *nnext; /* of the Bl body */ 1403 1404 nbody = mdoc->last; 1405 switch (nbody->type) { | 1300 sz = strlen(nn->string) + 1; 1301 break; 1302 } 1303 1304 if (0 != (ssz = macro2len(nn->tok))) 1305 sz = ssz; 1306 1307 break; --- 91 unchanged lines hidden (view full) --- 1399post_bl(POST_ARGS) 1400{ 1401 struct mdoc_node *nparent, *nprev; /* of the Bl block */ 1402 struct mdoc_node *nblock, *nbody; /* of the Bl */ 1403 struct mdoc_node *nchild, *nnext; /* of the Bl body */ 1404 1405 nbody = mdoc->last; 1406 switch (nbody->type) { |
1406 case MDOC_BLOCK: | 1407 case ROFFT_BLOCK: |
1407 post_bl_block(mdoc); 1408 return; | 1408 post_bl_block(mdoc); 1409 return; |
1409 case MDOC_HEAD: | 1410 case ROFFT_HEAD: |
1410 post_bl_head(mdoc); 1411 return; | 1411 post_bl_head(mdoc); 1412 return; |
1412 case MDOC_BODY: | 1413 case ROFFT_BODY: |
1413 break; 1414 default: 1415 return; 1416 } 1417 1418 nchild = nbody->child; 1419 if (nchild == NULL) { 1420 mandoc_msg(MANDOCERR_BLK_EMPTY, mdoc->parse, --- 58 unchanged lines hidden (view full) --- 1479 1480static void 1481post_bk(POST_ARGS) 1482{ 1483 struct mdoc_node *n; 1484 1485 n = mdoc->last; 1486 | 1414 break; 1415 default: 1416 return; 1417 } 1418 1419 nchild = nbody->child; 1420 if (nchild == NULL) { 1421 mandoc_msg(MANDOCERR_BLK_EMPTY, mdoc->parse, --- 58 unchanged lines hidden (view full) --- 1480 1481static void 1482post_bk(POST_ARGS) 1483{ 1484 struct mdoc_node *n; 1485 1486 n = mdoc->last; 1487 |
1487 if (n->type == MDOC_BLOCK && n->body->child == NULL) { | 1488 if (n->type == ROFFT_BLOCK && n->body->child == NULL) { |
1488 mandoc_msg(MANDOCERR_BLK_EMPTY, 1489 mdoc->parse, n->line, n->pos, "Bk"); 1490 mdoc_node_delete(mdoc, n); 1491 } 1492} 1493 1494static void 1495post_sm(struct mdoc *mdoc) 1496{ 1497 struct mdoc_node *nch; 1498 1499 nch = mdoc->last->child; 1500 1501 if (nch == NULL) { 1502 mdoc->flags ^= MDOC_SMOFF; 1503 return; 1504 } 1505 | 1489 mandoc_msg(MANDOCERR_BLK_EMPTY, 1490 mdoc->parse, n->line, n->pos, "Bk"); 1491 mdoc_node_delete(mdoc, n); 1492 } 1493} 1494 1495static void 1496post_sm(struct mdoc *mdoc) 1497{ 1498 struct mdoc_node *nch; 1499 1500 nch = mdoc->last->child; 1501 1502 if (nch == NULL) { 1503 mdoc->flags ^= MDOC_SMOFF; 1504 return; 1505 } 1506 |
1506 assert(nch->type == MDOC_TEXT); | 1507 assert(nch->type == ROFFT_TEXT); |
1507 1508 if ( ! strcmp(nch->string, "on")) { 1509 mdoc->flags &= ~MDOC_SMOFF; 1510 return; 1511 } 1512 if ( ! strcmp(nch->string, "off")) { 1513 mdoc->flags |= MDOC_SMOFF; 1514 return; --- 50 unchanged lines hidden (view full) --- 1565post_st(POST_ARGS) 1566{ 1567 struct mdoc_node *n, *nch; 1568 const char *p; 1569 1570 n = mdoc->last; 1571 nch = n->child; 1572 | 1508 1509 if ( ! strcmp(nch->string, "on")) { 1510 mdoc->flags &= ~MDOC_SMOFF; 1511 return; 1512 } 1513 if ( ! strcmp(nch->string, "off")) { 1514 mdoc->flags |= MDOC_SMOFF; 1515 return; --- 50 unchanged lines hidden (view full) --- 1566post_st(POST_ARGS) 1567{ 1568 struct mdoc_node *n, *nch; 1569 const char *p; 1570 1571 n = mdoc->last; 1572 nch = n->child; 1573 |
1573 assert(MDOC_TEXT == nch->type); | 1574 assert(nch->type == ROFFT_TEXT); |
1574 1575 if (NULL == (p = mdoc_a2st(nch->string))) { 1576 mandoc_vmsg(MANDOCERR_ST_BAD, mdoc->parse, 1577 nch->line, nch->pos, "St %s", nch->string); 1578 mdoc_node_delete(mdoc, n); 1579 } else { 1580 free(nch->string); 1581 nch->string = mandoc_strdup(p); 1582 } 1583} 1584 1585static void 1586post_rs(POST_ARGS) 1587{ 1588 struct mdoc_node *np, *nch, *next, *prev; 1589 int i, j; 1590 1591 np = mdoc->last; 1592 | 1575 1576 if (NULL == (p = mdoc_a2st(nch->string))) { 1577 mandoc_vmsg(MANDOCERR_ST_BAD, mdoc->parse, 1578 nch->line, nch->pos, "St %s", nch->string); 1579 mdoc_node_delete(mdoc, n); 1580 } else { 1581 free(nch->string); 1582 nch->string = mandoc_strdup(p); 1583 } 1584} 1585 1586static void 1587post_rs(POST_ARGS) 1588{ 1589 struct mdoc_node *np, *nch, *next, *prev; 1590 int i, j; 1591 1592 np = mdoc->last; 1593 |
1593 if (np->type != MDOC_BODY) | 1594 if (np->type != ROFFT_BODY) |
1594 return; 1595 1596 if (np->child == NULL) { 1597 mandoc_msg(MANDOCERR_RS_EMPTY, mdoc->parse, 1598 np->line, np->pos, "Rs"); 1599 return; 1600 } 1601 --- 76 unchanged lines hidden (view full) --- 1678 */ 1679static void 1680post_hyph(POST_ARGS) 1681{ 1682 struct mdoc_node *nch; 1683 char *cp; 1684 1685 for (nch = mdoc->last->child; nch != NULL; nch = nch->next) { | 1595 return; 1596 1597 if (np->child == NULL) { 1598 mandoc_msg(MANDOCERR_RS_EMPTY, mdoc->parse, 1599 np->line, np->pos, "Rs"); 1600 return; 1601 } 1602 --- 76 unchanged lines hidden (view full) --- 1679 */ 1680static void 1681post_hyph(POST_ARGS) 1682{ 1683 struct mdoc_node *nch; 1684 char *cp; 1685 1686 for (nch = mdoc->last->child; nch != NULL; nch = nch->next) { |
1686 if (nch->type != MDOC_TEXT) | 1687 if (nch->type != ROFFT_TEXT) |
1687 continue; 1688 cp = nch->string; 1689 if (*cp == '\0') 1690 continue; 1691 while (*(++cp) != '\0') 1692 if (*cp == '-' && 1693 isalpha((unsigned char)cp[-1]) && 1694 isalpha((unsigned char)cp[1])) --- 12 unchanged lines hidden (view full) --- 1707 1708static void 1709post_sh(POST_ARGS) 1710{ 1711 1712 post_ignpar(mdoc); 1713 1714 switch (mdoc->last->type) { | 1688 continue; 1689 cp = nch->string; 1690 if (*cp == '\0') 1691 continue; 1692 while (*(++cp) != '\0') 1693 if (*cp == '-' && 1694 isalpha((unsigned char)cp[-1]) && 1695 isalpha((unsigned char)cp[1])) --- 12 unchanged lines hidden (view full) --- 1708 1709static void 1710post_sh(POST_ARGS) 1711{ 1712 1713 post_ignpar(mdoc); 1714 1715 switch (mdoc->last->type) { |
1715 case MDOC_HEAD: | 1716 case ROFFT_HEAD: |
1716 post_sh_head(mdoc); 1717 break; | 1717 post_sh_head(mdoc); 1718 break; |
1718 case MDOC_BODY: | 1719 case ROFFT_BODY: |
1719 switch (mdoc->lastsec) { 1720 case SEC_NAME: 1721 post_sh_name(mdoc); 1722 break; 1723 case SEC_SEE_ALSO: 1724 post_sh_see_also(mdoc); 1725 break; 1726 case SEC_AUTHORS: --- 89 unchanged lines hidden (view full) --- 1816 1817 n = n->next; 1818 if (n == NULL) 1819 break; 1820 if (n->tok == MDOC_Xr) { 1821 lastpunct = "none"; 1822 continue; 1823 } | 1720 switch (mdoc->lastsec) { 1721 case SEC_NAME: 1722 post_sh_name(mdoc); 1723 break; 1724 case SEC_SEE_ALSO: 1725 post_sh_see_also(mdoc); 1726 break; 1727 case SEC_AUTHORS: --- 89 unchanged lines hidden (view full) --- 1817 1818 n = n->next; 1819 if (n == NULL) 1820 break; 1821 if (n->tok == MDOC_Xr) { 1822 lastpunct = "none"; 1823 continue; 1824 } |
1824 if (n->type != MDOC_TEXT) | 1825 if (n->type != ROFFT_TEXT) |
1825 break; 1826 for (name = n->string; *name != '\0'; name++) 1827 if (isalpha((const unsigned char)*name)) 1828 return; 1829 lastpunct = n->string; 1830 if (n->next == NULL) 1831 mandoc_vmsg(MANDOCERR_XR_PUNCT, mdoc->parse, 1832 n->line, n->pos, "%s after %s(%s)", --- 142 unchanged lines hidden (view full) --- 1975} 1976 1977static void 1978post_ignpar(POST_ARGS) 1979{ 1980 struct mdoc_node *np; 1981 1982 switch (mdoc->last->type) { | 1826 break; 1827 for (name = n->string; *name != '\0'; name++) 1828 if (isalpha((const unsigned char)*name)) 1829 return; 1830 lastpunct = n->string; 1831 if (n->next == NULL) 1832 mandoc_vmsg(MANDOCERR_XR_PUNCT, mdoc->parse, 1833 n->line, n->pos, "%s after %s(%s)", --- 142 unchanged lines hidden (view full) --- 1976} 1977 1978static void 1979post_ignpar(POST_ARGS) 1980{ 1981 struct mdoc_node *np; 1982 1983 switch (mdoc->last->type) { |
1983 case MDOC_HEAD: | 1984 case ROFFT_HEAD: |
1984 post_hyph(mdoc); 1985 return; | 1985 post_hyph(mdoc); 1986 return; |
1986 case MDOC_BODY: | 1987 case ROFFT_BODY: |
1987 break; 1988 default: 1989 return; 1990 } 1991 1992 if (NULL != (np = mdoc->last->child)) 1993 if (MDOC_Pp == np->tok || MDOC_Lp == np->tok) { 1994 mandoc_vmsg(MANDOCERR_PAR_SKIP, --- 14 unchanged lines hidden (view full) --- 2009} 2010 2011static void 2012pre_par(PRE_ARGS) 2013{ 2014 2015 if (NULL == mdoc->last) 2016 return; | 1988 break; 1989 default: 1990 return; 1991 } 1992 1993 if (NULL != (np = mdoc->last->child)) 1994 if (MDOC_Pp == np->tok || MDOC_Lp == np->tok) { 1995 mandoc_vmsg(MANDOCERR_PAR_SKIP, --- 14 unchanged lines hidden (view full) --- 2010} 2011 2012static void 2013pre_par(PRE_ARGS) 2014{ 2015 2016 if (NULL == mdoc->last) 2017 return; |
2017 if (MDOC_ELEM != n->type && MDOC_BLOCK != n->type) | 2018 if (n->type != ROFFT_ELEM && n->type != ROFFT_BLOCK) |
2018 return; 2019 2020 /* 2021 * Don't allow prior `Lp' or `Pp' prior to a paragraph-type 2022 * block: `Lp', `Pp', or non-compact `Bd' or `Bl'. 2023 */ 2024 2025 if (MDOC_Pp != mdoc->last->tok && --- 48 unchanged lines hidden (view full) --- 2074} 2075 2076static void 2077pre_literal(PRE_ARGS) 2078{ 2079 2080 pre_display(mdoc, n); 2081 | 2019 return; 2020 2021 /* 2022 * Don't allow prior `Lp' or `Pp' prior to a paragraph-type 2023 * block: `Lp', `Pp', or non-compact `Bd' or `Bl'. 2024 */ 2025 2026 if (MDOC_Pp != mdoc->last->tok && --- 48 unchanged lines hidden (view full) --- 2075} 2076 2077static void 2078pre_literal(PRE_ARGS) 2079{ 2080 2081 pre_display(mdoc, n); 2082 |
2082 if (MDOC_BODY != n->type) | 2083 if (n->type != ROFFT_BODY) |
2083 return; 2084 2085 /* 2086 * The `Dl' (note "el" not "one") and `Bd -literal' and `Bd 2087 * -unfilled' macros set MDOC_LITERAL on entrance to the body. 2088 */ 2089 2090 switch (n->tok) { --- 324 unchanged lines hidden --- | 2084 return; 2085 2086 /* 2087 * The `Dl' (note "el" not "one") and `Bd -literal' and `Bd 2088 * -unfilled' macros set MDOC_LITERAL on entrance to the body. 2089 */ 2090 2091 switch (n->tok) { --- 324 unchanged lines hidden --- |