File: strparse.3

package info (click to toggle)
xinetd 1%3A2.3.15.4-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,324 kB
  • sloc: ansic: 15,809; makefile: 207; sh: 165; perl: 92
file content (161 lines) | stat: -rw-r--r-- 4,078 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
.\"(c) Copyright 1992, 1993 by Panagiotis Tsirigotis
.\"All rights reserved.  The file named COPYRIGHT specifies the terms
.\"and conditions for redistribution.
.\"
.\" $Id$
.TH STRPARSE 3X "30 September 1992"
.SH NAME
str_parse, str_endparse, str_component, str_separator, str_nextpos
.SH SYNOPSIS
.LP
.nf
.ft B
#include "str.h"
.LP
.ft B
str_h str_parse( str, separ, flags, errnop )
char *str ;
char *separ ;
int flags ;
int *errnop ;
.LP
.ft B
void str_endparse( handle )
str_h handle ;
.LP
.ft B
char *str_component( handle )
str_h handle ;
.LP
.ft B
int str_setstr( handle, newstr )
str_h handle ;
char *newstr ;
.LP
.ft B
int str_separator( handle, separ )
str_h handle ;
char *separ ;
.LP
.ft B
char *str_nextpos( handle )
str_h handle ;
.LP
extern int str_errno ;
.SH DESCRIPTION
.LP
These functions are useful for parsing strings.  In this context
parsing means breaking the string into substrings. The substrings are
separated by a list of possible separator characters.
.LP
.B str_component()
returns successive substrings of the string.
.B str_parse()
creates and initializes a string parser with the string
that will be processed, \fIstr\fR, the list of possible separator
characters, \fIsepar\fR, and flags that control how the parser
works. The \fIflags\fR argument is formed by ORing one or more of
the following constants:
.TP 20
.SB STR_RETURN_ERROR
If something goes wrong return a value that indicates that an error occurred
(e.g. out of memory). The default is for the program to be terminated
with an appropriate error message.
.TP
.SB STR_NULL_START
If \fIstr\fR starts with a separator then a zero-length string will be returned
the first time \fBstr_component()\fR is called.
.TP
.SB STR_NULL_END
If \fIstr\fR ends with a separator then a zero-length string will be returned
by \fBstr_component()\fR when the substrings of \fIstr\fR are exhausted.
.TP
.SB STR_MALLOC
The strings returned by \fBstr_component()\fR will be in malloc'ed memory.
By default the substrings are part of \fIstr\fR.
If this option is not used \fIstr\fR will be modified
by \fBstr_component()\fR.
.LP
Finally, \fBSTR_NOFLAGS\fR may be used to specify no flags.
The \fIerrnop\fR argument points to an integer where the string processing
functions will deposit an error code if an error occurs.
If \fIerrnop\fR
is
.SM NULL
the error codes will be placed in \fIstr_errno\fR.
This is useful only if \fBSTR_RETURN_ERROR\fR is used in \fIflags\fR.
It is possible that \fIstr\fP is
.SM NULL.
In this case, a subsequent
.B str_setstr()
should be used to specify the string to be processed.
.LP
.B str_component()
returns successive substrings from the string associated with the
parser specified by \fIhandle\fR.
.LP
.B str_endparse()
destroys the parser specified by \fIhandle\fR.
.LP
.B str_setstr()
changes the processed string to \fInewstr\fP.
.LP
.B str_separator()
replaces the list of separator characters with \fIsepar\fR.
Processing continues from the current position.
.LP
.B str_nextpos()
returns a pointer to the rest of the string. The previous character
is a separator character (if \fBSTR_MALLOC\fR is not set, then the
previous character is
.SM NUL
).
.SH "RETURN VALUES"
.LP
.B str_parse()
returns a parser handle or
.SM NULL
if something goes wrong and \fIflags\fR & \fBSTR_RETURN_ERROR\fR is true.
Possible \fIstr_errno\fR values:
.RS
.TP 20
.SB STR_ENULLSEPAR
\fIsepar\fR is
.SM NULL
.TP
.SB STR_ENOMEM
the program ran out of memory
.RE
.LP
.B str_component()
returns a pointer to the next substring or
.SM NULL
if something goes wrong and \fIflags\fR & \fBSTR_RETURN_ERROR\fR is true.
.LP
.B str_setstr()
returns
.SB STR_OK
on success or
.SB STR_ERR
on failure.
.LP
.B str_separator()
returns
.SB STR_OK
on success or
.SB STR_ERR
on failure.
.LP
.B str_nextpos()
returns a pointer or
.SM NULL
if the end of string has been reached.
.SH BUGS
.B str_component()
modifies the string unless \fBSTR_MALLOC\fR is
set in the parser.
.LP
There should be only one parser active on a specific string. If there
is more than
one, they all must use the \fBSTR_MALLOC\fR option.