Pádraig Brady <[email protected]> writes:

> On 29/09/2025 04:39, Collin Funk wrote:
>> This patch moves some logic from 'fold' into a local Gnulib module that
>> can be used by other programs.
>> The module is used in a similar manner to getc (). Here is a trivial
>> example of it's use:
>>      #include "mbbuf.h"
>>      mcel_t g;
>>      while ((g = mbbuf_next_char (istream)).ch != MBBUF_EOF)
>>        fwrite (mbbuf_prev_char (g), 1, g.len, stdout);
>> This module should make it pretty easy to port programs who use getc
>> ()
>> and putc (). And it will make sure that invalid multi-byte characters
>> are treated consistently across programs.
>> Performance is the same as coreutils-9.8 since the logic isn't
>> really
>> changed.
>> Thoughts?
>
> Excellent idea.
>
> Given we've catered for various cases in fold(1),
> reusing that logic makes a lot of sense.
>
> mbbuf_get_char() + mbbuf_char_offset() may be preferable to
> mbbuf_next_char() + mbbuf_prev_char() ?

Yep, that looks better. I disliked the names myself, but was not feeling
creative enough to think of anything better.

> I'd change "first character in the previously read character" to
> "first _byte_ in the previously read character".
>
> The module Depends should add: c99, mcel.
>
> This gl module uses "ioblksize.h" which by right should
> thus made into a gl module so that gl modules are
> self contained / easy to move to gnulib.
> We can do that after anyway.
>
> There are a couple of minor `make syntax-check` issues.
>
> I'd change the license to the same as mcel (LGPLv2+)
> in case it's ever moved to gnulib.

Yep, I didn't run 'make syntax-check'. This patch was more of a RFC and
I was expecting it needed to be cleaned up.

I'm fine with making the mbbuf module LVPLv2+, but that would mean we
cannot use ioblksize.h since it is GPLv3+. We would have to re-license
that or use some other constant like BUFSIZ. What do you think?

Also, if moved to Gnulib I would remove the global variables and expect
pointers passed to the functions. I'm 50/50 on changing that right
now...

Collin

Reply via email to