diff options
author | millert <> | 1997-08-20 04:28:14 +0000 |
---|---|---|
committer | millert <> | 1997-08-20 04:28:14 +0000 |
commit | d9e9dd15aef27c2a7246403ea76898fa1a4c061a (patch) | |
tree | 3ea56483928248a93c3560051206ccfcceb1c614 /src/lib/libc/string/strsep.3 | |
parent | 4faa3305b950b8ac8eaa6c02f8d7099f2e0f623d (diff) | |
download | openbsd-d9e9dd15aef27c2a7246403ea76898fa1a4c061a.tar.gz openbsd-d9e9dd15aef27c2a7246403ea76898fa1a4c061a.tar.bz2 openbsd-d9e9dd15aef27c2a7246403ea76898fa1a4c061a.zip |
Update from lite2.
Diffstat (limited to 'src/lib/libc/string/strsep.3')
-rw-r--r-- | src/lib/libc/string/strsep.3 | 76 |
1 files changed, 47 insertions, 29 deletions
diff --git a/src/lib/libc/string/strsep.3 b/src/lib/libc/string/strsep.3 index 0cae3e0f1b..471e693ecc 100644 --- a/src/lib/libc/string/strsep.3 +++ b/src/lib/libc/string/strsep.3 | |||
@@ -1,8 +1,11 @@ | |||
1 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. | 1 | .\" $OpenBSD: strsep.3,v 1.3 1997/08/20 04:28:13 millert Exp $ |
2 | .\" All rights reserved. | 2 | .\" |
3 | .\" Copyright (c) 1990, 1991, 1993 | ||
4 | .\" The Regents of the University of California. All rights reserved. | ||
3 | .\" | 5 | .\" |
4 | .\" This code is derived from software contributed to Berkeley by | 6 | .\" This code is derived from software contributed to Berkeley by |
5 | .\" Chris Torek. | 7 | .\" Chris Torek. |
8 | .\" | ||
6 | .\" Redistribution and use in source and binary forms, with or without | 9 | .\" Redistribution and use in source and binary forms, with or without |
7 | .\" modification, are permitted provided that the following conditions | 10 | .\" modification, are permitted provided that the following conditions |
8 | .\" are met: | 11 | .\" are met: |
@@ -31,9 +34,9 @@ | |||
31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 34 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
32 | .\" SUCH DAMAGE. | 35 | .\" SUCH DAMAGE. |
33 | .\" | 36 | .\" |
34 | .\" $OpenBSD: strsep.3,v 1.2 1996/08/19 08:34:24 tholo Exp $ | 37 | .\" @(#)strsep.3 8.1 (Berkeley) 6/9/93 |
35 | .\" | 38 | .\" |
36 | .Dd April 19, 1991 | 39 | .Dd June 9, 1993 |
37 | .Dt STRSEP 3 | 40 | .Dt STRSEP 3 |
38 | .Os | 41 | .Os |
39 | .Sh NAME | 42 | .Sh NAME |
@@ -46,23 +49,29 @@ | |||
46 | .Sh DESCRIPTION | 49 | .Sh DESCRIPTION |
47 | The | 50 | The |
48 | .Fn strsep | 51 | .Fn strsep |
49 | locates in the null-terminated string at | 52 | function locates, in the string referenced by |
50 | .Fa *stringp | ||
51 | the first occurrence of any character in | ||
52 | .Fa delim | ||
53 | and replaces this with a | ||
54 | .Ql \e0 , | ||
55 | records the location of the immediate following character in | ||
56 | .Fa *stringp , | 53 | .Fa *stringp , |
57 | then returns the original value of | 54 | the first occurrence of any character in the string |
55 | .Fa delim | ||
56 | (or the terminating | ||
57 | .Ql \e0 | ||
58 | character) and replaces it with a | ||
59 | .Ql \e0 . | ||
60 | The location of the next character after the delimiter character | ||
61 | (or NULL, if the end of the string was reached) is stored in | ||
58 | .Fa *stringp . | 62 | .Fa *stringp . |
59 | If no delimiter characters are found, | 63 | The original value of |
60 | .Fn strsep | 64 | .Fa *stringp |
61 | sets | 65 | is returned. |
66 | .Pp | ||
67 | An ``empty'' field, i.e. one caused by two adjacent delimiter characters, | ||
68 | can be detected by comparing the location referenced by the pointer returned | ||
69 | in | ||
62 | .Fa *stringp | 70 | .Fa *stringp |
63 | to | 71 | to |
64 | .Dv NULL ; | 72 | .Ql \e0 . |
65 | if | 73 | .Pp |
74 | If | ||
66 | .Fa *stringp | 75 | .Fa *stringp |
67 | is initially | 76 | is initially |
68 | .Dv NULL , | 77 | .Dv NULL , |
@@ -72,20 +81,29 @@ returns | |||
72 | .Sh EXAMPLES | 81 | .Sh EXAMPLES |
73 | The following uses | 82 | The following uses |
74 | .Fn strsep | 83 | .Fn strsep |
75 | to parse strings containing runs of white space, | 84 | to parse a string, containing tokens delimited by white space, into an |
76 | making up an argument vector: | 85 | argument vector: |
77 | .Bd -literal -offset indent | 86 | .Bd -literal -offset indent |
78 | char inputstring[100]; | 87 | char **ap, *argv[10], *inputstring; |
79 | char **argv[51], **ap = argv, *p, *val; | 88 | |
80 | /* set up inputstring */ | 89 | for (ap = argv; (*ap = strsep(&inputstring, " \et")) != NULL;) |
81 | for (p = inputstring; p != NULL; ) { | 90 | if (**ap != '\e0') |
82 | while ((val = strsep(&p, " \et")) != NULL && *val == '\e0'); | 91 | ++ap; |
83 | *ap++ = val; | ||
84 | } | ||
85 | *ap = 0; | ||
86 | .Ed | 92 | .Ed |
87 | .Sh HISTORY | 93 | .Sh HISTORY |
88 | The | 94 | The |
89 | .Fn strsep | 95 | .Fn strsep |
90 | function is | 96 | function |
91 | .Ud . | 97 | is intended as a replacement for the |
98 | .Fn strtok | ||
99 | function. | ||
100 | While the | ||
101 | .Fn strtok | ||
102 | function should be preferred for portability reasons (it conforms to | ||
103 | .St -ansiC ) | ||
104 | it is unable to handle empty fields, i.e. detect fields delimited by | ||
105 | two adjacent delimiter characters, or to be used for more than a single | ||
106 | string at a time. | ||
107 | The | ||
108 | .Fn strsep | ||
109 | function first appeared in 4.4BSD. | ||