[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [bug-gawk] How to print an unsigned char?
From: |
Andrew J. Schorr |
Subject: |
Re: [bug-gawk] How to print an unsigned char? |
Date: |
Mon, 25 Feb 2019 08:09:09 -0500 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
I don't disagree. My suggestion was somewhat tongue-in-cheek, but it is
possible. After all, we now have a readfile extension that can suck in binary
data. If we had an extension library that offered read and write calls, plus a
couple of functions to convert back and forth between arrays of integers and
binary strings, we'd be in business. I don't know why this is desirable, but
it's possible. I guess if we wanted to have a socket library and the
possibility of interacting with servers that use a non-textual protocol, this
might be appealing. It does seem like an odd thing to attempt using the AWK
language though.
Regards,
Andy
On Mon, Feb 25, 2019 at 12:23:57AM -0700, 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
> > >
> > >
>
--
Andrew Schorr e-mail: address@hidden
Telemetry Investments, L.L.C. phone: 917-305-1748
545 Fifth Ave, Suite 1108 fax: 212-425-5550
New York, NY 10017-3630
- Re: [bug-gawk] How to print an unsigned char?, (continued)
- Re: [bug-gawk] How to print an unsigned char?, david kerns, 2019/02/19
- Re: [bug-gawk] How to print an unsigned char?, Peng Yu, 2019/02/24
- Re: [bug-gawk] How to print an unsigned char?, Eli Zaretskii, 2019/02/24
- Message not available
- Re: [bug-gawk] How to print an unsigned char?, Eli Zaretskii, 2019/02/24
- Re: [bug-gawk] How to print an unsigned char?, Peng Yu, 2019/02/24
- Re: [bug-gawk] How to print an unsigned char?, Andrew J. Schorr, 2019/02/24
- Re: [bug-gawk] How to print an unsigned char?, Wolfgang Laun, 2019/02/25
- Re: [bug-gawk] How to print an unsigned char?, arnold, 2019/02/25
- Re: [bug-gawk] How to print an unsigned char?, Wolfgang Laun, 2019/02/25
- Re: [bug-gawk] How to print an unsigned char?, arnold, 2019/02/25
- Re: [bug-gawk] How to print an unsigned char?,
Andrew J. Schorr <=
- Re: [bug-gawk] How to print an unsigned char?, arnold, 2019/02/24