1 .\" $Id: roff.3,v 1.4 2010/07/03 16:02:12 schwarze Exp $
3 .\" Copyright (c) 2010 Kristaps Dzonsons <kristaps@bsd.lv>
5 .\" Permission to use, copy, modify, and distribute this software for any
6 .\" purpose with or without fee is hereby granted, provided that the above
7 .\" copyright notice and this permission notice appear in all copies.
9 .\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 .\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 .\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 .\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 .\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 .Dd $Mdocdate: July 3 2010 $
27 .Nd roff macro compiler library
34 .Fa "struct regset *regs"
39 .Fn roff_endparse "struct roff *roff"
41 .Fn roff_free "struct roff *roff"
44 .Fa "struct roff *roff"
52 .Fn roff_reset "struct roff *roff"
55 .Fn roff_setstr "const char *name" "const char *string"
57 .Fn roff_getstr "const char *name"
59 .Fn roff_getstrn "const char *name" "size_t len"
65 library processes lines of
69 In general, applications initiate a parsing sequence with
71 parse each line in a document with
73 close the parsing session with
75 and finally free all allocated memory with
79 function may be used in order to reset the parser for another input
84 function should be invoked before passing a line into the
92 section for a full example.
94 This section further defines the
98 available to programmers.
102 may use the following types:
104 .It Vt "enum rofferr"
105 Instructions for further processing to the caller of
108 An opaque type defined in
110 Its values are only used privately within the library.
112 A function callback type defined in
116 Function descriptions follow:
119 Allocates a parsing structure.
126 arguments are defined in
128 Returns NULL on failure.
129 If non-NULL, the pointer must be freed with
132 Reset the parser for another parse routine.
135 behaves as if invoked for the first time.
137 Free all resources of a parser.
138 The pointer is no longer valid after invocation.
140 Parse a nil-terminated line of input.
143 may be modified or reallocated within this function.
146 will be modified accordingly.
149 pointer will be modified if the line start during subsequent processing
150 of the line is not at the zeroth index.
151 This line should not contain the trailing newline.
152 Returns 0 on failure, 1 on success.
154 Signals that the parse is complete.
155 Returns 0 on failure, 1 on success.
157 .Sh USER-DEFINED STRINGS
158 Strings defined by the
161 instruction are saved using the
163 function and retrieved using the
169 These functions take the name of the string to be accessed
170 as their first argument.
173 requires the name to be null-terminated,
175 accepts non-terminated strings, but requires the length of the name
178 The second argument to
180 is the new value of the string.
181 It will be copied to internal storage, so both pointers to constant
182 strings and pointers to volatile storage are acceptable.
184 All of these functions return a pointer to the new value of the string
185 in internal storage, which should be considered read-only, so use
187 on it as appropriate.
188 The read functions return NULL when a string of the specified name
189 is not available or empty, and
191 returns NULL when memory allocation fails.
192 In the latter case, the string will remain unset.
196 clears all user-defined strings.
206 in the source distribution for an example of usage.
215 library was written by
216 .An Kristaps Dzonsons Aq kristaps@bsd.lv .
218 The implementation of user-defined strings needs improvement:
221 String values are taken literally and are not interpreted.
223 Parsing of quoted strings is incomplete.
225 The stings are stored internally using a singly linked list,
226 which is fine for small numbers of strings,
227 but ineffient when handling many strings.