aboutsummaryrefslogtreecommitdiffstats
path: root/lispref/processes.texi
diff options
context:
space:
mode:
Diffstat (limited to 'lispref/processes.texi')
-rw-r--r--lispref/processes.texi70
1 files changed, 39 insertions, 31 deletions
diff --git a/lispref/processes.texi b/lispref/processes.texi
index 9eb733236a9..0f0b617e36c 100644
--- a/lispref/processes.texi
+++ b/lispref/processes.texi
@@ -2185,11 +2185,11 @@ field name is specified, the value is bound to that field name.
2185@var{form} can access and update these dynamically bound variables: 2185@var{form} can access and update these dynamically bound variables:
2186 2186
2187@table @code 2187@table @code
2188@item raw-data 2188@item bindat-raw
2189The data as a byte array. 2189The data as a byte array.
2190 2190
2191@item pos 2191@item bindat-idx
2192Current position of the unpacking or packing operation. 2192Current index into bindat-raw of the unpacking or packing operation.
2193 2193
2194@item struct 2194@item struct
2195Alist. 2195Alist.
@@ -2231,23 +2231,26 @@ of @var{form}. A non-@code{nil} result indicates a match.
2231@end itemize 2231@end itemize
2232 2232
2233@item repeat @var{count} @var{field-spec}@dots{} 2233@item repeat @var{count} @var{field-spec}@dots{}
2234Process the set of @var{field-spec}s recursively, in order, and loop
2235starting from the first one, for @var{count} times overall (looping
2236@code{@var{count} @minus{} 1} times).
2234@var{count} may be an integer, or a list of one element naming a 2237@var{count} may be an integer, or a list of one element naming a
2235previous field. For correct operation, each @var{field-spec} must 2238previous field. For correct operation, each @var{field-spec} must
2236include a name. 2239include a name.
2237@c ??? What does it MEAN?
2238@end table 2240@end table
2239 2241
2240@node Bindat Functions 2242@node Bindat Functions
2241@subsection Functions to Unpack and Pack Bytes 2243@subsection Functions to Unpack and Pack Bytes
2242 2244
2243 In the following documentation, @var{spec} refers to a data layout 2245 In the following documentation, @var{spec} refers to a data layout
2244specification, @code{raw-data} to a byte array, and @var{struct} to an 2246specification, @code{bindat-raw} to a byte array, and @var{struct} to an
2245alist representing unpacked field data. 2247alist representing unpacked field data.
2246 2248
2247@defun bindat-unpack spec raw-data &optional pos 2249@defun bindat-unpack spec bindat-raw &optional bindat-idx
2248This function unpacks data from the byte array @code{raw-data} 2250This function unpacks data from the unibyte string or byte
2251array @code{bindat-raw}
2249according to @var{spec}. Normally this starts unpacking at the 2252according to @var{spec}. Normally this starts unpacking at the
2250beginning of the byte array, but if @var{pos} is non-@code{nil}, it 2253beginning of the byte array, but if @var{bindat-idx} is non-@code{nil}, it
2251specifies a zero-based starting position to use instead. 2254specifies a zero-based starting position to use instead.
2252 2255
2253The value is an alist or nested alist in which each element describes 2256The value is an alist or nested alist in which each element describes
@@ -2267,23 +2270,29 @@ field @code{c} in the third element of subfield @code{b} of field
2267@code{a}. (This corresponds to @code{struct.a.b[2].c} in C.) 2270@code{a}. (This corresponds to @code{struct.a.b[2].c} in C.)
2268@end defun 2271@end defun
2269 2272
2273 Although packing and unpacking operations change the organization of
2274data (in memory), they preserve the data's @dfn{total length}, which is
2275the sum of all the fields' lengths, in bytes. This value is not
2276generally inherent in either the specification or alist alone; instead,
2277both pieces of information contribute to its calculation. Likewise, the
2278length of a string or array being unpacked may be longer than the data's
2279total length as described by the specification.
2280
2270@defun bindat-length spec struct 2281@defun bindat-length spec struct
2271@c ??? I don't understand this at all -- rms 2282This function returns the total length of the data in @var{struct},
2272This function returns the length in bytes of @var{struct}, according 2283according to @var{spec}.
2273to @var{spec}.
2274@end defun 2284@end defun
2275 2285
2276@defun bindat-pack spec struct &optional raw-data pos 2286@defun bindat-pack spec struct &optional bindat-raw bindat-idx
2277This function returns a byte array packed according to @var{spec} from 2287This function returns a byte array packed according to @var{spec} from
2278the data in the alist @var{struct}. Normally it creates and fills a 2288the data in the alist @var{struct}. Normally it creates and fills a
2279new byte array starting at the beginning. However, if @var{raw-data} 2289new byte array starting at the beginning. However, if @var{bindat-raw}
2280is non-@code{nil}, it specifies a pre-allocated string or vector to 2290is non-@code{nil}, it specifies a pre-allocated unibyte string or vector to
2281pack into. If @var{pos} is non-@code{nil}, it specifies the starting 2291pack into. If @var{bindat-idx} is non-@code{nil}, it specifies the starting
2282offset for packing into @code{raw-data}. 2292offset for packing into @code{bindat-raw}.
2283 2293
2284@c ??? Isn't this a bug? Shouldn't it always be unibyte? 2294When pre-allocating, you should make sure @code{(length @var{bindat-raw})}
2285Note: The result is a multibyte string; use @code{string-make-unibyte} 2295meets or exceeds the total length to avoid an out-of-range error.
2286on it to make it unibyte if necessary.
2287@end defun 2296@end defun
2288 2297
2289@defun bindat-ip-to-string ip 2298@defun bindat-ip-to-string ip
@@ -2367,18 +2376,17 @@ COOKIES, indicates the border between entries."
2367 (with-temp-buffer 2376 (with-temp-buffer
2368 (set-buffer-multibyte nil) 2377 (set-buffer-multibyte nil)
2369 (insert 2378 (insert
2370 (string-make-unibyte 2379 (bindat-pack
2371 (bindat-pack 2380 fcookie-index-spec
2372 fcookie-index-spec 2381 `((:version . 2)
2373 `((:version . 2) 2382 (:count . ,count)
2374 (:count . ,count) 2383 (:longest . ,max)
2375 (:longest . ,max) 2384 (:shortest . ,min)
2376 (:shortest . ,min) 2385 (:flags . 0)
2377 (:flags . 0) 2386 (:delim . ,delim)
2378 (:delim . ,delim) 2387 (:offset . ,(mapcar (lambda (o)
2379 (:offset . ,(mapcar (lambda (o) 2388 (list (cons :foo o)))
2380 (list (cons :foo o))) 2389 (nreverse offsets))))))
2381 (nreverse offsets)))))))
2382 (let ((coding-system-for-write 'raw-text-unix)) 2390 (let ((coding-system-for-write 'raw-text-unix))
2383 (write-file (or index (concat cookies ".dat"))))))) 2391 (write-file (or index (concat cookies ".dat")))))))
2384@end lisp 2392@end lisp