summaryrefslogtreecommitdiff
path: root/static/v10/man3/getfields.3
diff options
context:
space:
mode:
Diffstat (limited to 'static/v10/man3/getfields.3')
-rw-r--r--static/v10/man3/getfields.374
1 files changed, 74 insertions, 0 deletions
diff --git a/static/v10/man3/getfields.3 b/static/v10/man3/getfields.3
new file mode 100644
index 00000000..2f0b90ce
--- /dev/null
+++ b/static/v10/man3/getfields.3
@@ -0,0 +1,74 @@
+.TH GETFIELDS 3
+.CT 2 data_man
+.SH NAME
+getfields, getmfields, setfields \(mi break a string into fields
+.SH SYNOPSIS
+.nf
+.B int getfields(str, ptrs, nptrs)
+.B char *str, **ptrs;
+.PP
+.B int getmfields(str, ptrs, nptrs)
+.B char *str, **ptrs;
+.PP
+.B void setfields(fielddelim)
+.B char *fielddelim;
+.fi
+.SH DESCRIPTION
+.I Getfields
+breaks the null-terminated string
+.I str
+into at most
+.I nptrs
+null-terminated fields and places pointers to the start of these fields in the array
+.IR ptrs .
+It returns the number of fields
+and terminates the list of pointers with a zero pointer.
+It overwrites some of the bytes in
+.IR str .
+If there are
+.I nptr
+or more fields, the list will not end with zero
+and the last `field' will extend to the end of the
+input string and may contain delimiters.
+.PP
+A field is defined as a maximal sequence of characters not in a set
+of field delimiters.
+Adjacent fields are separated by exactly one delimiter.
+No field follows a delimiter at the end of string.
+Thus a string of just two delimiter characters
+contains two empty fields,
+and a nonempty string with no delimiters contains
+one field.
+.PP
+.I Getmfields
+is the same as
+.I getfields
+except that fields are separated by maximal strings of
+field delimiters rather than just one.
+.PP
+.I Setfields
+makes the field delimiters (space and tab by default)
+be the characters of the string
+.I fielddelim.
+.SH EXAMPLES
+Print the words in a string, where words are non-whitespace
+strings.
+There is no bound on the number of words.
+.EX
+printwords(string)
+char *string;
+{
+ char *ptrs[2];
+ int n;
+ setfields(" \et\en");
+ for(n=2; n>=2; string=ptrs[1]) {
+ n = getmfields(string, ptrs, 2);
+ if(n == 0)
+ break;
+ if(ptrs[0][0] != 0) /* skip initial blanks */
+ printf("%s\en", ptrs[0]);
+ }
+}
+.EE
+.SH SEE ALSO
+.IR string (3)