all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bindat docs on length of str, strz, etc types
@ 2006-12-27 22:22 Kevin Ryde
  2006-12-27 23:06 ` Kim F. Storm
  0 siblings, 1 reply; 6+ messages in thread
From: Kevin Ryde @ 2006-12-27 22:22 UTC (permalink / raw)


In the "Bindat Spec" node of the lisp manual, the `repeat' type has

	COUNT may be an integer, or a list of one element that names a
	previous field.

If I'm not mistaken that applies to any of the LEN arguments for str,
strz, etc too (the "Bindat Examples" have some like that).  I wonder
if the words could be in a more prominent / more general spot.

And also if I'm not mistaken a form `(eval FOO)' is allowed, for
calculating a length.  It'd be nice to describe that.

I tried it for a jpeg record, where the length field includes itself
so the data is "length-2" bytes

	((marker u16)
	 (length u16)
	 (data   str (eval (- (assoc-default 'length struct) 2))))

But perhaps there's a cleaner way I missed.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: bindat docs on length of str, strz, etc types
  2006-12-27 22:22 bindat docs on length of str, strz, etc types Kevin Ryde
@ 2006-12-27 23:06 ` Kim F. Storm
  2006-12-27 23:38   ` Kevin Ryde
  0 siblings, 1 reply; 6+ messages in thread
From: Kim F. Storm @ 2006-12-27 23:06 UTC (permalink / raw)
  Cc: emacs-devel

Kevin Ryde <user42@zip.com.au> writes:

> In the "Bindat Spec" node of the lisp manual, the `repeat' type has
>
> 	COUNT may be an integer, or a list of one element that names a
> 	previous field.
>
> If I'm not mistaken that applies to any of the LEN arguments for str,
> strz, etc too (the "Bindat Examples" have some like that).  I wonder
> if the words could be in a more prominent / more general spot.
>
> And also if I'm not mistaken a form `(eval FOO)' is allowed, for
> calculating a length.  

You are right.  And all (eval FOO) forms can access `last' and
the other items listed only for the last type of eval form.

>                        It'd be nice to describe that.

Indeed.

>
> I tried it for a jpeg record, where the length field includes itself
> so the data is "length-2" bytes
>
> 	((marker u16)
> 	 (length u16)
> 	 (data   str (eval (- (assoc-default 'length struct) 2))))
>
> But perhaps there's a cleaner way I missed.

This should work:

	((marker u16)
	 (length u16)
	 (data   str (eval (- last 2))))


-- 
Kim F. Storm <storm@cua.dk> http://www.cua.dk

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: bindat docs on length of str, strz, etc types
  2006-12-27 23:06 ` Kim F. Storm
@ 2006-12-27 23:38   ` Kevin Ryde
  2006-12-29  1:23     ` Kim F. Storm
  0 siblings, 1 reply; 6+ messages in thread
From: Kevin Ryde @ 2006-12-27 23:38 UTC (permalink / raw)
  Cc: emacs-devel

storm@cua.dk (Kim F. Storm) writes:
>
> 	((marker u16)
> 	 (length u16)
> 	 (data   str (eval (- last 2))))

Thanks, it works.

While you're at it, I got a bit confused by strz at first.  I wanted
to match a variable-length field that stopped at a 0 byte and I tried
leaving out the length, which didn't work of course.  Maybe it could
say something like

	A zero-terminated string, in a fixed-length field of LEN bytes.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: bindat docs on length of str, strz, etc types
  2006-12-27 23:38   ` Kevin Ryde
@ 2006-12-29  1:23     ` Kim F. Storm
  2006-12-29 22:42       ` Kevin Ryde
  0 siblings, 1 reply; 6+ messages in thread
From: Kim F. Storm @ 2006-12-29  1:23 UTC (permalink / raw)
  Cc: emacs-devel

Kevin Ryde <user42@zip.com.au> writes:

> While you're at it, I got a bit confused by strz at first.  I wanted
> to match a variable-length field that stopped at a 0 byte and I tried
> leaving out the length, which didn't work of course.  Maybe it could
> say something like
>
> 	A zero-terminated string, in a fixed-length field of LEN bytes.


Thank you.

I have now updated the bindat docs according to your suggestions.
Please have a look.

-- 
Kim F. Storm <storm@cua.dk> http://www.cua.dk

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: bindat docs on length of str, strz, etc types
  2006-12-29  1:23     ` Kim F. Storm
@ 2006-12-29 22:42       ` Kevin Ryde
  2006-12-30  0:46         ` Kim F. Storm
  0 siblings, 1 reply; 6+ messages in thread
From: Kevin Ryde @ 2006-12-29 22:42 UTC (permalink / raw)
  Cc: emacs-devel

storm@cua.dk (Kim F. Storm) writes:
>
> I have now updated the bindat docs according to your suggestions.
> Please have a look.

I'm unsure about this bit

	In this case, the length can be given either by that field's
	name as specified for `bindat-get-field'

Should it say you write "(fieldname)" instead of a bare name.  Perhaps
if the "([NAME] HANDLER)" bit was at the start of the section you
could refer back to that instead of forward to bindat-get-field too.
Also maybe an @multitable could show the possibilities better than
words.  I suspect it's one of those things where patterns or examples
are easier to follow than actual description. :)

	integer        fixed given length
	(FIELDNAME)    length from a previous field
	(eval FORM)    length from evaluating FORM (more on eval below)

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: bindat docs on length of str, strz, etc types
  2006-12-29 22:42       ` Kevin Ryde
@ 2006-12-30  0:46         ` Kim F. Storm
  0 siblings, 0 replies; 6+ messages in thread
From: Kim F. Storm @ 2006-12-30  0:46 UTC (permalink / raw)
  Cc: emacs-devel

Kevin Ryde <user42@zip.com.au> writes:

> 	In this case, the length can be given either by that field's
> 	name as specified for `bindat-get-field'
>
> Should it say you write "(fieldname)" instead of a bare name.  

It should say it is a list, as you can use more than a single
(fieldname) element - just like in as the name arg to
bindat-get-field, e.g. (fn1 fn2).

>                                                                Perhaps
> if the "([NAME] HANDLER)" bit was at the start of the section you
> could refer back to that instead of forward to bindat-get-field too.

Well, it is more complex than a simple name.

-- 
Kim F. Storm <storm@cua.dk> http://www.cua.dk

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2006-12-30  0:46 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-12-27 22:22 bindat docs on length of str, strz, etc types Kevin Ryde
2006-12-27 23:06 ` Kim F. Storm
2006-12-27 23:38   ` Kevin Ryde
2006-12-29  1:23     ` Kim F. Storm
2006-12-29 22:42       ` Kevin Ryde
2006-12-30  0:46         ` Kim F. Storm

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.