]>
git.cameronkatri.com Git - mandoc.git/blob - roff.c
1 /* $Id: roff.c,v 1.103 2010/12/01 10:21:25 kristaps Exp $ */
3 * Copyright (c) 2010 Kristaps Dzonsons <kristaps@bsd.lv>
4 * Copyright (c) 2010 Ingo Schwarze <schwarze@openbsd.org>
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
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.
32 #include "libmandoc.h"
34 #define RSTACK_MAX 128
37 ('.' == (c) || '\'' == (c))
40 #define ROFF_DEBUG(fmt, args...) \
41 do { /* Nothing. */ } while (/*CONSTCOND*/ 0)
43 #define ROFF_DEBUG(fmt, args...) \
44 do { fprintf(stderr, fmt , ##args); } while (/*CONSTCOND*/ 0)
66 ROFF_ccond
, /* FIXME: remove this. */
78 char *name
; /* key of symbol */
79 char *string
; /* current value */
80 struct roffstr
*next
; /* next in list */
84 struct roffnode
*last
; /* leaf of stack */
85 mandocmsg msg
; /* err/warn/fatal messages */
86 void *data
; /* privdata for messages */
87 enum roffrule rstack
[RSTACK_MAX
]; /* stack of !`ie' rules */
88 int rstackpos
; /* position in rstack */
89 struct regset
*regs
; /* read/writable registers */
90 struct roffstr
*first_string
;
94 enum rofft tok
; /* type of node */
95 struct roffnode
*parent
; /* up one in stack */
96 int line
; /* parse line */
97 int col
; /* parse col */
98 char *end
; /* end-rules: custom token */
99 int endspan
; /* end-rules: next-line or infty */
100 enum roffrule rule
; /* current evaluation rule */
103 #define ROFF_ARGS struct roff *r, /* parse ctx */ \
104 enum rofft tok, /* tok of macro */ \
105 char **bufp, /* input buffer */ \
106 size_t *szp, /* size of input buffer */ \
107 int ln, /* parse line */ \
108 int ppos, /* original pos in buffer */ \
109 int pos, /* current pos in buffer */ \
110 int *offs /* reset offset of buffer data */
112 typedef enum rofferr (*roffproc
)(ROFF_ARGS
);
115 const char *name
; /* macro name */
116 roffproc proc
; /* process new macro */
117 roffproc text
; /* process as child text of macro */
118 roffproc sub
; /* process as child of macro */
120 #define ROFFMAC_STRUCT (1 << 0) /* always interpret */
121 struct roffmac
*next
;
124 static enum rofferr
roff_block(ROFF_ARGS
);
125 static enum rofferr
roff_block_text(ROFF_ARGS
);
126 static enum rofferr
roff_block_sub(ROFF_ARGS
);
127 static enum rofferr
roff_cblock(ROFF_ARGS
);
128 static enum rofferr
roff_ccond(ROFF_ARGS
);
129 static enum rofferr
roff_cond(ROFF_ARGS
);
130 static enum rofferr
roff_cond_text(ROFF_ARGS
);
131 static enum rofferr
roff_cond_sub(ROFF_ARGS
);
132 static enum rofferr
roff_ds(ROFF_ARGS
);
133 static enum roffrule
roff_evalcond(const char *, int *);
134 static void roff_freestr(struct roff
*);
135 static const char *roff_getstrn(const struct roff
*,
136 const char *, size_t);
137 static enum rofferr
roff_line_ignore(ROFF_ARGS
);
138 static enum rofferr
roff_nr(ROFF_ARGS
);
139 static int roff_res(struct roff
*,
140 char **, size_t *, int);
141 static void roff_setstr(struct roff
*,
142 const char *, const char *);
143 static char *roff_strdup(const char *);
145 /* See roff_hash_find() */
149 #define HASHWIDTH (ASCII_HI - ASCII_LO + 1)
151 static struct roffmac
*hash
[HASHWIDTH
];
153 static struct roffmac roffs
[ROFF_MAX
] = {
154 { "ad", roff_line_ignore
, NULL
, NULL
, 0, NULL
},
155 { "am", roff_block
, roff_block_text
, roff_block_sub
, 0, NULL
},
156 { "ami", roff_block
, roff_block_text
, roff_block_sub
, 0, NULL
},
157 { "am1", roff_block
, roff_block_text
, roff_block_sub
, 0, NULL
},
158 { "de", roff_block
, roff_block_text
, roff_block_sub
, 0, NULL
},
159 { "dei", roff_block
, roff_block_text
, roff_block_sub
, 0, NULL
},
160 { "de1", roff_block
, roff_block_text
, roff_block_sub
, 0, NULL
},
161 { "ds", roff_ds
, NULL
, NULL
, 0, NULL
},
162 { "el", roff_cond
, roff_cond_text
, roff_cond_sub
, ROFFMAC_STRUCT
, NULL
},
163 { "hy", roff_line_ignore
, NULL
, NULL
, 0, NULL
},
164 { "ie", roff_cond
, roff_cond_text
, roff_cond_sub
, ROFFMAC_STRUCT
, NULL
},
165 { "if", roff_cond
, roff_cond_text
, roff_cond_sub
, ROFFMAC_STRUCT
, NULL
},
166 { "ig", roff_block
, roff_block_text
, roff_block_sub
, 0, NULL
},
167 { "ne", roff_line_ignore
, NULL
, NULL
, 0, NULL
},
168 { "nh", roff_line_ignore
, NULL
, NULL
, 0, NULL
},
169 { "rm", roff_line_ignore
, NULL
, NULL
, 0, NULL
},
170 { "tr", roff_line_ignore
, NULL
, NULL
, 0, NULL
},
171 { ".", roff_cblock
, NULL
, NULL
, 0, NULL
},
172 { "\\}", roff_ccond
, NULL
, NULL
, 0, NULL
},
173 { "nr", roff_nr
, NULL
, NULL
, 0, NULL
},
176 static void roff_free1(struct roff
*);
177 static enum rofft
roff_hash_find(const char *);
178 static void roff_hash_init(void);
179 static void roffnode_cleanscope(struct roff
*);
180 static void roffnode_push(struct roff
*,
181 enum rofft
, int, int);
182 static void roffnode_pop(struct roff
*);
183 static enum rofft
roff_parse(const char *, int *);
184 static int roff_parse_nat(const char *, unsigned int *);
186 /* See roff_hash_find() */
187 #define ROFF_HASH(p) (p[0] - ASCII_LO)
195 for (i
= 0; i
< (int)ROFF_MAX
; i
++) {
196 assert(roffs
[i
].name
[0] >= ASCII_LO
);
197 assert(roffs
[i
].name
[0] <= ASCII_HI
);
199 buc
= ROFF_HASH(roffs
[i
].name
);
201 if (NULL
!= (n
= hash
[buc
])) {
202 for ( ; n
->next
; n
= n
->next
)
206 hash
[buc
] = &roffs
[i
];
212 * Look up a roff token by its name. Returns ROFF_MAX if no macro by
213 * the nil-terminated string name could be found.
216 roff_hash_find(const char *p
)
222 * libroff has an extremely simple hashtable, for the time
223 * being, which simply keys on the first character, which must
224 * be printable, then walks a chain. It works well enough until
228 if (p
[0] < ASCII_LO
|| p
[0] > ASCII_HI
)
233 if (NULL
== (n
= hash
[buc
]))
235 for ( ; n
; n
= n
->next
)
236 if (0 == strcmp(n
->name
, p
))
237 return((enum rofft
)(n
- roffs
));
244 * Pop the current node off of the stack of roff instructions currently
248 roffnode_pop(struct roff
*r
)
255 if (ROFF_el
== p
->tok
)
256 if (r
->rstackpos
> -1)
259 ROFF_DEBUG("roff: popping scope\n");
260 r
->last
= r
->last
->parent
;
268 * Push a roff node onto the instruction stack. This must later be
269 * removed with roffnode_pop().
272 roffnode_push(struct roff
*r
, enum rofft tok
, int line
, int col
)
276 p
= mandoc_calloc(1, sizeof(struct roffnode
));
281 p
->rule
= p
->parent
? p
->parent
->rule
: ROFFRULE_DENY
;
288 roff_free1(struct roff
*r
)
298 roff_reset(struct roff
*r
)
306 roff_free(struct roff
*r
)
315 roff_alloc(struct regset
*regs
, void *data
, const mandocmsg msg
)
319 r
= mandoc_calloc(1, sizeof(struct roff
));
331 * Pre-filter each and every line for reserved words (one beginning with
332 * `\*', e.g., `\*(ab'). These must be handled before the actual line
336 roff_res(struct roff
*r
, char **bufp
, size_t *szp
, int pos
)
338 const char *cp
, *cpp
, *st
, *res
;
344 for (cp
= &(*bufp
)[pos
]; (cpp
= strstr(cp
, "\\*")); cp
++) {
362 for (i
= 0; 0 == maxl
|| i
< maxl
; i
++, cp
++) {
364 return(1); /* Error. */
365 if (0 == maxl
&& ']' == *cp
)
369 res
= roff_getstrn(r
, st
, (size_t)i
);
376 ROFF_DEBUG("roff: splicing reserved: [%.*s]\n", i
, st
);
378 nsz
= *szp
+ strlen(res
) + 1;
379 n
= mandoc_malloc(nsz
);
383 strlcat(n
, *bufp
, (size_t)(cpp
- *bufp
+ 1));
384 strlcat(n
, res
, nsz
);
385 strlcat(n
, cp
+ (maxl
? 0 : 1), nsz
);
399 roff_parseln(struct roff
*r
, int ln
, char **bufp
,
400 size_t *szp
, int pos
, int *offs
)
406 * Run the reserved-word filter only if we have some reserved
410 if (r
->first_string
&& ! roff_res(r
, bufp
, szp
, pos
))
414 * First, if a scope is open and we're not a macro, pass the
415 * text through the macro's filter. If a scope isn't open and
416 * we're not a macro, just let it through.
419 if (r
->last
&& ! ROFF_CTL((*bufp
)[pos
])) {
421 assert(roffs
[t
].text
);
422 ROFF_DEBUG("roff: intercept scoped text: %s, [%s]\n",
423 roffs
[t
].name
, &(*bufp
)[pos
]);
424 return((*roffs
[t
].text
)
426 ln
, pos
, pos
, offs
));
427 } else if ( ! ROFF_CTL((*bufp
)[pos
]))
431 * If a scope is open, go to the child handler for that macro,
432 * as it may want to preprocess before doing anything with it.
437 assert(roffs
[t
].sub
);
438 ROFF_DEBUG("roff: intercept scoped context: %s, [%s]\n",
439 roffs
[t
].name
, &(*bufp
)[pos
]);
440 return((*roffs
[t
].sub
)
442 ln
, pos
, pos
, offs
));
446 * Lastly, as we've no scope open, try to look up and execute
447 * the new macro. If no macro is found, simply return and let
448 * the compilers handle it.
452 if (ROFF_MAX
== (t
= roff_parse(*bufp
, &pos
)))
455 ROFF_DEBUG("roff: intercept new-scope: %s, [%s]\n",
456 roffs
[t
].name
, &(*bufp
)[pos
]);
457 assert(roffs
[t
].proc
);
458 return((*roffs
[t
].proc
)
460 ln
, ppos
, pos
, offs
));
465 roff_endparse(struct roff
*r
)
470 return((*r
->msg
)(MANDOCERR_SCOPEEXIT
, r
->data
, r
->last
->line
,
471 r
->last
->col
, NULL
));
476 * Parse a roff node's type from the input buffer. This must be in the
477 * form of ".foo xxx" in the usual way.
480 roff_parse(const char *buf
, int *pos
)
486 assert(ROFF_CTL(buf
[*pos
]));
489 while (buf
[*pos
] && (' ' == buf
[*pos
] || '\t' == buf
[*pos
]))
492 if ('\0' == buf
[*pos
])
495 for (j
= 0; j
< 4; j
++, (*pos
)++)
496 if ('\0' == (mac
[j
] = buf
[*pos
]))
498 else if (' ' == buf
[*pos
] || (j
&& '\\' == buf
[*pos
]))
506 if (ROFF_MAX
== (t
= roff_hash_find(mac
)))
509 while (buf
[*pos
] && ' ' == buf
[*pos
])
517 roff_parse_nat(const char *buf
, unsigned int *res
)
523 lval
= strtol(buf
, &ep
, 10);
524 if (buf
[0] == '\0' || *ep
!= '\0')
526 if ((errno
== ERANGE
&&
527 (lval
== LONG_MAX
|| lval
== LONG_MIN
)) ||
528 (lval
> INT_MAX
|| lval
< 0))
531 *res
= (unsigned int)lval
;
538 roff_cblock(ROFF_ARGS
)
542 * A block-close `..' should only be invoked as a child of an
543 * ignore macro, otherwise raise a warning and just ignore it.
546 if (NULL
== r
->last
) {
547 if ( ! (*r
->msg
)(MANDOCERR_NOSCOPE
, r
->data
, ln
, ppos
, NULL
))
552 switch (r
->last
->tok
) {
568 if ( ! (*r
->msg
)(MANDOCERR_NOSCOPE
, r
->data
, ln
, ppos
, NULL
))
574 if ( ! (*r
->msg
)(MANDOCERR_ARGSLOST
, r
->data
, ln
, pos
, NULL
))
578 roffnode_cleanscope(r
);
585 roffnode_cleanscope(struct roff
*r
)
589 if (--r
->last
->endspan
< 0)
598 roff_ccond(ROFF_ARGS
)
601 if (NULL
== r
->last
) {
602 if ( ! (*r
->msg
)(MANDOCERR_NOSCOPE
, r
->data
, ln
, ppos
, NULL
))
607 switch (r
->last
->tok
) {
615 if ( ! (*r
->msg
)(MANDOCERR_NOSCOPE
, r
->data
, ln
, ppos
, NULL
))
620 if (r
->last
->endspan
> -1) {
621 if ( ! (*r
->msg
)(MANDOCERR_NOSCOPE
, r
->data
, ln
, ppos
, NULL
))
627 if ( ! (*r
->msg
)(MANDOCERR_ARGSLOST
, r
->data
, ln
, pos
, NULL
))
631 roffnode_cleanscope(r
);
638 roff_block(ROFF_ARGS
)
643 if (ROFF_ig
!= tok
&& '\0' == (*bufp
)[pos
]) {
644 if ( ! (*r
->msg
)(MANDOCERR_NOARGS
, r
->data
, ln
, ppos
, NULL
))
647 } else if (ROFF_ig
!= tok
) {
648 while ((*bufp
)[pos
] && ' ' != (*bufp
)[pos
])
650 while (' ' == (*bufp
)[pos
])
654 roffnode_push(r
, tok
, ln
, ppos
);
656 if ('\0' == (*bufp
)[pos
])
660 while ((*bufp
)[pos
] && ' ' != (*bufp
)[pos
] &&
661 '\t' != (*bufp
)[pos
])
665 * Note: groff does NOT like escape characters in the input.
666 * Instead of detecting this, we're just going to let it fly and
671 sz
= (size_t)(pos
- sv
);
673 if (1 == sz
&& '.' == (*bufp
)[sv
])
676 r
->last
->end
= mandoc_malloc(sz
+ 1);
678 memcpy(r
->last
->end
, *bufp
+ sv
, sz
);
679 r
->last
->end
[(int)sz
] = '\0';
682 if ( ! (*r
->msg
)(MANDOCERR_ARGSLOST
, r
->data
, ln
, pos
, NULL
))
691 roff_block_sub(ROFF_ARGS
)
697 * First check whether a custom macro exists at this level. If
698 * it does, then check against it. This is some of groff's
699 * stranger behaviours. If we encountered a custom end-scope
700 * tag and that tag also happens to be a "real" macro, then we
701 * need to try interpreting it again as a real macro. If it's
702 * not, then return ignore. Else continue.
707 while (' ' == (*bufp
)[i
] || '\t' == (*bufp
)[i
])
710 for (j
= 0; r
->last
->end
[j
]; j
++, i
++)
711 if ((*bufp
)[i
] != r
->last
->end
[j
])
714 if ('\0' == r
->last
->end
[j
] &&
715 ('\0' == (*bufp
)[i
] ||
717 '\t' == (*bufp
)[i
])) {
719 roffnode_cleanscope(r
);
721 if (ROFF_MAX
!= roff_parse(*bufp
, &pos
))
728 * If we have no custom end-query or lookup failed, then try
729 * pulling it out of the hashtable.
733 t
= roff_parse(*bufp
, &pos
);
735 /* If we're not a comment-end, then throw it away. */
736 if (ROFF_cblock
!= t
)
739 assert(roffs
[t
].proc
);
740 return((*roffs
[t
].proc
)(r
, t
, bufp
, szp
,
741 ln
, ppos
, pos
, offs
));
747 roff_block_text(ROFF_ARGS
)
756 roff_cond_sub(ROFF_ARGS
)
765 * Clean out scope. If we've closed ourselves, then don't
769 roffnode_cleanscope(r
);
771 if (ROFF_MAX
== (t
= roff_parse(*bufp
, &pos
))) {
772 if ('\\' == (*bufp
)[pos
] && '}' == (*bufp
)[pos
+ 1])
774 (r
, ROFF_ccond
, bufp
, szp
,
775 ln
, pos
, pos
+ 2, offs
));
776 return(ROFFRULE_DENY
== rr
? ROFF_IGN
: ROFF_CONT
);
780 * A denied conditional must evaluate its children if and only
781 * if they're either structurally required (such as loops and
782 * conditionals) or a closing macro.
784 if (ROFFRULE_DENY
== rr
)
785 if ( ! (ROFFMAC_STRUCT
& roffs
[t
].flags
))
789 assert(roffs
[t
].proc
);
790 return((*roffs
[t
].proc
)(r
, t
, bufp
, szp
,
791 ln
, ppos
, pos
, offs
));
797 roff_cond_text(ROFF_ARGS
)
805 * We display the value of the text if out current evaluation
806 * scope permits us to do so.
809 /* FIXME: use roff_ccond? */
812 if (NULL
== (ep
= strstr(st
, "\\}"))) {
813 roffnode_cleanscope(r
);
814 return(ROFFRULE_DENY
== rr
? ROFF_IGN
: ROFF_CONT
);
817 if (ep
== st
|| (ep
> st
&& '\\' != *(ep
- 1)))
820 roffnode_cleanscope(r
);
821 return(ROFFRULE_DENY
== rr
? ROFF_IGN
: ROFF_CONT
);
826 roff_evalcond(const char *v
, int *pos
)
832 return(ROFFRULE_ALLOW
);
839 return(ROFFRULE_DENY
);
844 while (v
[*pos
] && ' ' != v
[*pos
])
846 return(ROFFRULE_DENY
);
852 roff_line_ignore(ROFF_ARGS
)
866 /* Stack overflow! */
868 if (ROFF_ie
== tok
&& r
->rstackpos
== RSTACK_MAX
- 1) {
869 (*r
->msg
)(MANDOCERR_MEM
, r
->data
, ln
, ppos
, NULL
);
873 /* First, evaluate the conditional. */
875 if (ROFF_el
== tok
) {
877 * An `.el' will get the value of the current rstack
878 * entry set in prior `ie' calls or defaults to DENY.
880 if (r
->rstackpos
< 0)
881 rule
= ROFFRULE_DENY
;
883 rule
= r
->rstack
[r
->rstackpos
];
885 rule
= roff_evalcond(*bufp
, &pos
);
889 while (' ' == (*bufp
)[pos
])
893 * Roff is weird. If we have just white-space after the
894 * conditional, it's considered the BODY and we exit without
895 * really doing anything. Warn about this. It's probably
899 if ('\0' == (*bufp
)[pos
] && sv
!= pos
) {
900 if ((*r
->msg
)(MANDOCERR_NOARGS
, r
->data
, ln
, ppos
, NULL
))
905 roffnode_push(r
, tok
, ln
, ppos
);
907 r
->last
->rule
= rule
;
909 ROFF_DEBUG("roff: cond: %s -> %s\n", roffs
[tok
].name
,
910 ROFFRULE_ALLOW
== rule
? "allow" : "deny");
912 if (ROFF_ie
== tok
) {
914 * An if-else will put the NEGATION of the current
915 * evaluated conditional into the stack.
918 if (ROFFRULE_DENY
== r
->last
->rule
)
919 r
->rstack
[r
->rstackpos
] = ROFFRULE_ALLOW
;
921 r
->rstack
[r
->rstackpos
] = ROFFRULE_DENY
;
924 /* If the parent has false as its rule, then so do we. */
926 if (r
->last
->parent
&& ROFFRULE_DENY
== r
->last
->parent
->rule
) {
927 r
->last
->rule
= ROFFRULE_DENY
;
928 ROFF_DEBUG("roff: cond override: %s -> deny\n",
933 * Determine scope. If we're invoked with "\{" trailing the
934 * conditional, then we're in a multiline scope. Else our scope
935 * expires on the next line.
938 r
->last
->endspan
= 1;
940 if ('\\' == (*bufp
)[pos
] && '{' == (*bufp
)[pos
+ 1]) {
941 r
->last
->endspan
= -1;
943 ROFF_DEBUG("roff: cond-scope: %s, multi-line\n",
946 ROFF_DEBUG("roff: cond-scope: %s, one-line\n",
950 * If there are no arguments on the line, the next-line scope is
954 if ('\0' == (*bufp
)[pos
])
957 /* Otherwise re-run the roff parser after recalculating. */
971 * A symbol is named by the first word following the macro
972 * invocation up to a space. Its value is anything after the
973 * name's trailing whitespace and optional double-quote. Thus,
977 * will have `bar " ' as its value.
985 /* Read until end of name. */
986 while (*string
&& ' ' != *string
)
989 /* Nil-terminate name. */
993 /* Read past spaces. */
994 while (*string
&& ' ' == *string
)
997 /* Read passed initial double-quote. */
998 if (*string
&& '"' == *string
)
1001 /* The rest is the value. */
1002 roff_setstr(r
, name
, string
);
1011 const char *key
, *val
;
1014 key
= &(*bufp
)[pos
];
1017 /* Parse register request. */
1018 while ((*bufp
)[pos
] && ' ' != (*bufp
)[pos
])
1022 * Set our nil terminator. Because this line is going to be
1023 * ignored anyway, we can munge it as we please.
1026 (*bufp
)[pos
++] = '\0';
1028 /* Skip whitespace to register token. */
1029 while ((*bufp
)[pos
] && ' ' == (*bufp
)[pos
])
1032 val
= &(*bufp
)[pos
];
1034 /* Process register token. */
1036 if (0 == strcmp(key
, "nS")) {
1037 rg
[(int)REG_nS
].set
= 1;
1038 if ( ! roff_parse_nat(val
, &rg
[(int)REG_nS
].v
.u
))
1039 rg
[(int)REG_nS
].v
.u
= 0;
1041 ROFF_DEBUG("roff: register nS: %u\n",
1042 rg
[(int)REG_nS
].v
.u
);
1044 ROFF_DEBUG("roff: ignoring register: %s\n", key
);
1051 roff_strdup(const char *name
)
1053 char *namecopy
, *sv
;
1056 * This isn't a nice simple mandoc_strdup() because we must
1057 * handle roff's stupid double-escape rule.
1059 sv
= namecopy
= mandoc_malloc(strlen(name
) + 1);
1061 if ('\\' == *name
&& '\\' == *(name
+ 1))
1063 *namecopy
++ = *name
++;
1072 roff_setstr(struct roff
*r
, const char *name
, const char *string
)
1077 n
= r
->first_string
;
1078 while (n
&& strcmp(name
, n
->name
))
1082 namecopy
= mandoc_strdup(name
);
1083 n
= mandoc_malloc(sizeof(struct roffstr
));
1085 n
->next
= r
->first_string
;
1086 r
->first_string
= n
;
1090 /* Don't use mandoc_strdup: clean out double-escapes. */
1091 n
->string
= string
? roff_strdup(string
) : NULL
;
1092 ROFF_DEBUG("roff: new symbol: [%s] = [%s]\n", name
, n
->string
);
1097 roff_getstrn(const struct roff
*r
, const char *name
, size_t len
)
1099 const struct roffstr
*n
;
1101 n
= r
->first_string
;
1102 while (n
&& (strncmp(name
, n
->name
, len
) || '\0' != n
->name
[(int)len
]))
1105 return(n
? n
->string
: NULL
);
1110 roff_freestr(struct roff
*r
)
1112 struct roffstr
*n
, *nn
;
1114 for (n
= r
->first_string
; n
; n
= nn
) {
1121 r
->first_string
= NULL
;