1 .\" $Id: roff.3,v 1.5 2010/07/04 22:04:04 schwarze 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.
18 .Dd $Mdocdate: July 4 2010 $
28 .Nd roff macro compiler library
35 .Fa "struct regset *regs"
40 .Fn roff_endparse "struct roff *roff"
42 .Fn roff_free "struct roff *roff"
45 .Fa "struct roff *roff"
53 .Fn roff_reset "struct roff *roff"
56 .Fn roff_setstr "const char *name" "const char *string"
58 .Fn roff_getstr "const char *name"
60 .Fn roff_getstrn "const char *name" "size_t len"
66 library processes lines of
70 In general, applications initiate a parsing sequence with
72 parse each line in a document with
74 close the parsing session with
76 and finally free all allocated memory with
80 function may be used in order to reset the parser for another input
85 function should be invoked before passing a line into the
93 section for a full example.
95 This section further defines the
99 available to programmers.
103 may use the following types:
105 .It Vt "enum rofferr"
106 Instructions for further processing to the caller of
109 An opaque type defined in
111 Its values are only used privately within the library.
113 A function callback type defined in
117 Function descriptions follow:
120 Allocates a parsing structure.
127 arguments are defined in
129 Returns NULL on failure.
130 If non-NULL, the pointer must be freed with
133 Reset the parser for another parse routine.
136 behaves as if invoked for the first time.
138 Free all resources of a parser.
139 The pointer is no longer valid after invocation.
141 Parse a nil-terminated line of input.
144 may be modified or reallocated within this function.
147 will be modified accordingly.
150 pointer will be modified if the line start during subsequent processing
151 of the line is not at the zeroth index.
152 This line should not contain the trailing newline.
153 Returns 0 on failure, 1 on success.
155 Signals that the parse is complete.
156 Returns 0 on failure, 1 on success.
158 .Sh USER-DEFINED STRINGS
159 Strings defined by the
162 instruction are saved using the
164 function and retrieved using the
170 These functions take the name of the string to be accessed
171 as their first argument.
174 requires the name to be null-terminated,
176 accepts non-terminated strings, but requires the length of the name
179 The second argument to
181 is the new value of the string.
182 It will be copied to internal storage, so both pointers to constant
183 strings and pointers to volatile storage are acceptable.
185 All of these functions return a pointer to the new value of the string
186 in internal storage, which should be considered read-only, so use
188 on it as appropriate.
189 The read functions return NULL when a string of the specified name
190 is not available or empty, and
192 returns NULL when memory allocation fails.
193 In the latter case, the string will remain unset.
197 clears all user-defined strings.
207 in the source distribution for an example of usage.
216 library was written by
217 .An Kristaps Dzonsons Aq kristaps@bsd.lv .
219 The implementation of user-defined strings needs improvement:
222 String values are taken literally and are not interpreted.
224 Parsing of quoted strings is incomplete.
226 The stings are stored internally using a singly linked list,
227 which is fine for small numbers of strings,
228 but ineffient when handling many strings.