[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 2/3] ios: Move file name normalization logic into ios-dev.h
From: |
Jose E. Marchesi |
Subject: |
Re: [PATCH 2/3] ios: Move file name normalization logic into ios-dev.h |
Date: |
Tue, 14 Jul 2020 01:37:26 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
On 7/12/20 11:32 AM, Jose E. Marchesi wrote:
> Hi Ege.
>
> +#define IOS_FILE_HANDLER_NORMALIZE(handler, newhandler)
\
> +{
\
> + /* File devices are special, in the sense that they accept any
\
> + handler. However, we want to ensure that the ios name is
\
> + unambiguous from other ios devices, by prepending ./ to
relative \
> + names that might otherwise be confusing. */
\
> + static const char safe[] =
\
> + "abcdefghijklmnopqrstuvwxyz"
\
> + "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
\
> + "0123456789/+_-";
\
> +
\
> + if (handler[0] == '/' || strspn (handler, safe) == strlen
(handler)) \
> + (newhandler) = strdup ((handler));
\
> +
\
> + if (asprintf (&(newhandler), "./%s", (handler)) == -1)
\
> + (newhandler) = NULL;
\
> +}
>
> Maybe it would be better to use a static inline function here?
> Otherwise, please surround the macro body with do..while(0)
>
> Other than that, OK for master.
> Thanks! :)
I am not happy with the implicit declaration warnings due to asprintf,
with including stdio.h here or adding pragmas.
I am keeping it as the macro for now. In nearby-future, if
ios-dev-stream and ios-dev-file end up sharing more code, we can
consider getting those two a new .h file exclusively.
I added the do-while upon your request and pushed the changes.
Ok, thanks :)
I played with the stream IOS implementation using the following little
Poke implementation of `strings' (yeah, it is the first Poke filter ever
written, and as you can see it uses the strategy we foresaw at Mont
Soleil):
-----<-------
#!/usr/local/bin/poke -L
!#
/* Printable ASCII characters: 0x20..0x7e */
defvar stdin = open ("<stdin>");
defvar stdout = open ("<stdout>");
defvar offset = 0#B;
try
{
flush (stdin, offset);
defvar b = byte @ stdin : offset;
if (b >= 0x20 && b <= 0x7e)
byte @ stdout : iosize (stdout) = b;
offset = offset + 1#B;
}
until E_eof;
close (stdin);
close (stdout);
------>-------
It works, up to some point:
$ cat /usr/bin/ncal | ./pstrings
poke: ../../libpoke/ios-buffer.h:244: ios_buffer_forget_till: Assertion
`buffer->end_offset >= buffer->begin_offset' failed.
ELF> @m@8@@@@888WW ]] Aborted (core dumped)
This is very exciting :)
[PATCH 3/3] ios: Pass "flags" to handler_normalize as an argument., Egeyar Bagcioglu, 2020/07/11
Re: [PATCH 1/3] ios: Introduce ios_flush and ios_dev_<...>_flush., Jose E. Marchesi, 2020/07/12