bug-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug-gawk] How to print an unsigned char?


From: Wolfgang Laun
Subject: Re: [bug-gawk] How to print an unsigned char?
Date: Mon, 25 Feb 2019 08:34:42 +0100

That's what I think, too. With the things you've mentioned it would be
terribly awkward. Java hides the memory representation, and look at the
heavy artillery they need to let you do binary i/o. OK, I shoots very well,
but at a price. You don't want this in (g)awk.

Thanks
Wolfgang

On Mon, 25 Feb 2019 at 08:23, <address@hidden> wrote:

> Awk and gawk are the wrong language to use for binary I/O.
>
> If you insist on doing stuff like that, first use the -b option, so
> that each byte in a string is treated as a character on it own.
> Next, you can use the lshift, rshift, or, xor, and "and" functions to
> do bit manipulations if you really want to.
>
> But I really think that trying to use gawk for serious bit manipulation
> and binary I/O is forcing a square peg into a round hole, and won't work
> well.
>
> Arnold
>
> Wolfgang Laun <address@hidden> wrote:
>
> > Having the system calls read and write as functions is only one part of
> the
> > cake. You'd need to have a data type that can play the role of the char[]
> > used as data buffer in these calls *with a well-defined, portable memory
> > representation. *As an example: how to compose something with the size of
> > 10 memory units (bytes) consisting of the lowermost 1/2/3/4 bytes of
> > a/b/c/d, densely packed?
> >
> > (I have browsed the gawk user manual's sections that sound relevant.
> Sorry
> > if I missed this being already available.)
> > Wolfgang
> >
> >
> > On Mon, 25 Feb 2019 at 00:07, Andrew J. Schorr <
> > address@hidden> wrote:
> >
> > > On Sun, Feb 24, 2019 at 02:40:54PM -0600, Peng Yu wrote:
> > > > On 2/24/19, Eli Zaretskii <address@hidden> wrote:
> > > > > [Please use Reply All, please don't take this off-list.]
> > > > >
> > > > >> From: Peng Yu <address@hidden>
> > > > >> Date: Sun, 24 Feb 2019 12:11:45 -0600
> > > > >>
> > > > >> > Yes, don't use %c.
> > > > >> How?
> > > > >
> > > > > It depends on what you want to accomplish.  Can you describe your
> > > > > goal(s) in this matter?
> > > >
> > > > As the title says "How to print an unsigned char?"
> > >
> > > This can be done using the extension API. The get_file hook provides
> > > access to
> > > the file descriptor via the returned awk_input_buf_t or
> awk_output_buf_t.
> > > The
> > > select extension uses this in the "input_fd" and "output_fd"
> functions. So
> > > it
> > > should be fairly simple to create an extension that provides access to
> the
> > > read
> > > & write system calls for a gawk "file". We will eventually need this if
> > > anybody
> > > wants to implement a socket library.
> > >
> > > So it's simple: write a new gawk extension implementing read and
> write, and
> > > then you can use those functions to do binary I/O. Or just use Python
> > > where the
> > > file objects can be accessed through the high-level print function or
> the
> > > low-level read and write methods.
> > >
> > > Regards,
> > > Andy
> > >
> > >
>


reply via email to

[Prev in Thread] Current Thread [Next in Thread]