source: trunk/third/ispell/fields.3 @ 10334

Revision 10334, 9.1 KB checked in by ghudson, 27 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r10333, which included commits to RCS files with non-trunk default branches.
Line 
1.\"
2.\" $Id: fields.3,v 1.1.1.1 1997-09-03 21:08:08 ghudson Exp $
3.\"
4.\" $Log: not supported by cvs2svn $
5.\" Revision 1.3  1994/01/05  20:13:43  geoff
6.\" Add the maxf parameter
7.\"
8.\" Revision 1.2  1994/01/04  02:40:16  geoff
9.\" Add descriptions of field_line_inc, field_field_inc, and the
10.\" FLD_NOSHRINK flag.
11.\"
12.\" Revision 1.1  1993/09/09  01:09:44  geoff
13.\" Initial revision
14.\"
15.\"
16.TH FIELDS 3 local
17.SH NAME
18fieldread, fieldmake, fieldwrite, fieldfree \- field access package
19.SH SYNTAX
20.nf
21#include "fields.h"
22
23typedef struct {
24    int nfields;
25    int hadnl;
26    char *linebuf;
27    char **fields;
28} field_t;
29
30#define FLD_RUNS        0x0001
31#define FLD_SNGLQUOTES  0x0002
32#define FLD_BACKQUOTES  0x0004
33#define FLD_DBLQUOTES   0x0008
34#define FLD_SHQUOTES    0x0010
35#define FLD_STRIPQUOTES 0x0020
36#define FLD_BACKSLASH   0x0040
37
38extern field_t *fieldread (FILE * file, char * delims,
39                           int flags, int maxf);
40extern field_t *fieldmake (char * line, int allocated,
41                           char * delims, int flags, int maxf);
42extern int fieldwrite (FILE * file, field_t * fieldp,
43                       int delim);
44extern void fieldfree (field_t * fieldp);
45
46extern unsigned int field_line_inc;
47extern unsigned int field_field_inc;
48.fi
49.SH DESCRIPTION
50.PP
51The fields access package eases the common task of parsing and
52accessing information which is separated into fields by whitespace or
53other delimiters.  Various options can be specified to handle many
54common cases, including selectable delimiters, runs of delimiters, and
55quoting.
56.PP
57.I fieldread
58reads one line from a file, parses it into fields as specified by the
59parameters, and returns a
60.B field_t
61structure describing the result.
62.I fieldmake
63performs the same process on a buffer already in memory.
64.I fieldwrite
65creates an output line from a
66.B field_t
67structure and writes it to an output file.
68.I fieldfree
69frees a
70.B field_t
71structure and any associated memory allocated by the package.
72.PP
73The
74.B field_t
75structure describes the fields in a parsed line.
76A well-behaved should only access the
77.BR nfields ,
78.BR fields ,
79and
80.B hadnl
81elements;
82all other elements are used internally by the package and are not
83guaranteed to remain the same even though they are documented here.
84.B Nfields
85gives the number of fields in the parsed line, just like the
86.B argc
87argument to a C program;
88.B fields
89is a pointer to an array of string pointers, just like the
90.B argv
91argument to a C program.
92As in C, the last field pointer is followed by a null pointer,
93although the field count is the preferred method of accessing fields.
94The user may alter
95.B nfields
96by decreasing it, and may replace any pointer in
97.B fields
98without harm.
99This is often useful in replacing a single field with a calculated
100value preparatory to output.
101The
102.B hadnl
103element is nonzero if the original line was terminated with a newline
104when it was parsed;
105this is used to accurately reproduce the input when
106.I fieldwrite
107is called.
108.PP
109The
110.B linebuf
111element contains a pointer to an internal buffer allocated by
112.I fieldread
113or provided to
114.IR fieldmake .
115This buffer is
116.I not
117guaranteed to contain anything sensible, although in the current
118implementation all of the field contents can be found therein.
119.PP
120.I fieldread
121reads a single line of arbitrary length from
122.BR file ,
123allocating as much memory as necessary to hold it, and then parses the
124line according to its remaining arguments.
125A pointer to the parsed
126.B field_t
127structure is returned, with
128.B NULL
129returned if an error occurs or if
130.B EOF
131is reached on the input file.
132Fields in the input line are considered to be separated by any of the
133delimiters in the
134.B delims
135parameter.
136For example, if delimiters of ":.;" are specified, a line containing
137"a:b;c.d" would be considered to have four fields.
138.PP
139The default parsing of fields considers each delimiter to indicate a
140separate field, and does not allow any quoting.  This is similar to
141the parsing done by
142.IR cut (1).
143This behavior can be modified by specifying flags.
144Multiple flags may be OR'ed together.
145The available flags are:
146.IP \fBFLD_RUNS\fP
147Consider runs of delimiters to be the same as a single delimiter,
148suppressing all null fields.
149This is similar to the way utilities like
150.IR awk (1)
151and
152.IR sort (1)
153treat whitespace, but it is not limited to whitespace.
154A run does not have to consist of a single type of delimiter;  if both
155semicolon and colon are delimiters, ";::;" is a run.
156.IP \fBFLD_SNGLQUOTES\fP
157Allow field contents to be quoted with single quotes.
158Delimiters and other quotes appearing within single quotes are ignored.
159This may appear in combination with other quote options.
160.IP \fBFLD_BACKQUOTES\fP
161Allow field contents to be quoted with reverse single quotes.
162Delimiters and other quotes appearing within reverse single quotes are ignored.
163This may appear in combination with other quote options.
164.IP \fBFLD_DBLQUOTES\fP
165Allow field contents to be quoted with single quotes.
166Delimiters and other quotes appearing within double quotes are ignored.
167This may appear in combination with other quote options.
168.IP \fBFLD_SHQUOTES\fP
169Allow shell-style quoting.
170In the absence of this option, quotes are only recognized at the
171beginning of a field, and characters following the close quote are
172removed from the field (and are thus lost from the input line).
173If this option is specified, quotes may appear within a field, in the
174same way as they are handled by
175.IR sh (1).
176Multiple quoting styles may be used in the same field.
177If none of
178.BR FLD_SNGLQUOTES ,
179.BR FLD_BACKQUOTES ,
180or
181.B FLD_DBLQUOTES
182is specified with
183.BR FLD_SHQUOTES ,
184all three options are implied.
185.IP \fBFLD_STRIPQUOTES\fP
186Remove quotes and backslash sequences from the field while parsing,
187converting backslash sequences to their proper ASCII equivalent.
188The C sequences \ea, \eb, \ef, \en, \er, \ev, \ex\fInn\fP, and \e\fInnn\fP are
189supported.
190Any other sequence is simply converted to the backslashed character,
191as in
192.IR sh (1).
193.IP \fBFLD_BACKSLASH\fP
194Accept standard C-style backslash sequences.
195The sequence will be converted to an ASCII equivalent if
196.B FLD_STRIPQUOTES
197is specified (q.v.).
198.IP \fBFLD_NOSHRINK\fP
199Don't shrink allocated memory using
200.IR realloc (3)
201before returning.
202This option can have a significant effect on performance, especially
203when
204.I fieldfree
205is going to be called soon after
206.I fieldread
207or
208.IR fieldmake .
209The disadvantage is that slightly more memory will be occupied until
210the field structure is freed.
211.PP
212The
213.I maxf
214parameter, if nonzero, specifies the maximum number of fields to be
215generated.
216This may enhance performance if only the first few fields of a long
217line are of interest to the caller.
218The actual number of fields returned is one greater than
219.IR maxf ,
220because the remainder of the line will be returned as a single
221contiguous (and uninterpreted,
222.B FLD_STRIPQUOTES
223or
224.B FLD_BACKSLASH
225is specified) field.
226.PP
227.I fieldmake
228operates exactly like
229.IR fieldread ,
230except that the line parsed is provided by the caller rather than
231being read from a file.
232If the
233.I allocated
234parameter is nonzero, the memory pointed to by the
235.I line
236parameter will automatically be freed when
237.I fieldfree
238is called;
239otherwise this memory is the caller's responsibility.
240The memory pointed to by
241.I line
242is destroyed by
243.IR fieldmake .
244All other parameters are the same as for
245.IR fieldread.
246.PP
247.I fieldwrite
248writes a set of fields to the specified
249.IR file ,
250separating them with the delimiter character
251.I delim
252(note that this is a character, not a string), and appending a newline
253if specified by the
254.I hadnl
255element of the structure.
256The field structure is not freed.
257.I fieldwrite
258will return nonzero if an I/O error is detected.
259.PP
260.I fieldfree
261frees the
262.B field_t
263structure passed to it, along with any associated auxiliary memory
264allocated by the package (or passed to
265.IR fieldmake ).
266The structure may not be accessed after
267.I fieldfree
268is called.
269.PP
270.B field_line_inc
271(default 512) and
272.B field_field_inc
273(default 20) describe the increments to use when expanding lines as
274they are read in and parsed.
275.I fieldread
276initially allocates a buffer of
277.B field_line_inc
278bytes and, if the input line is larger than that, expands the buffer
279in increments of the same amount until it is large enough.
280If input lines are known to consistently reach a certain size,
281performance will be improved by setting
282.B field_line_inc
283to a value larger than that size (larger because there must be room
284for a null byte).
285.B field_field_inc
286serves the same purpose in both
287.I fieldread
288and
289.IR fieldmake ,
290except that it is related to the number of fields in the line rather
291than to the line length.
292If the number of fields is known, performance will be improved by
293setting
294.B field_field_inc
295to at least one more than that number.
296.SH RETURN VALUES
297.I fieldread
298and
299.I fieldmake
300return
301.B NULL
302if an error occurs or if
303.B EOF
304is reached on the input file.
305.I fieldwrite
306returns nonzero if an output error occurs.
307.SH BUGS
308Thanks to the vagaries of ANSI C, the
309.B fields.h
310header file defines an auxiliary macro named
311.BR P .
312If the user needs a similarly-named macro, this macro must be
313undefined first, and the user's macro must be defined after
314.B fields.h
315is included.
Note: See TracBrowser for help on using the repository browser.