Re: [dev] [PATCH][RFC] Add a basic version of tr

From: Silvan Jegen <s.jegen_AT_gmail.com>
Date: Thu, 16 Jan 2014 11:31:10 +0100

On Thu, Jan 16, 2014 at 1:41 AM, Szabolcs Nagy <nsz_AT_port70.net> wrote:
> * Silvan Jegen <s.jegen_AT_gmail.com> [2014-01-15 22:32:28 +0100]:
>> On Wed, Jan 15, 2014 at 09:36:07PM +0100, Szabolcs Nagy wrote:
>> > > +handleescapes(char *s)
>> > > +{
>> > > + switch(*s) {
>> > > + case 'n':
>> > > + *s = '\x0A';
>> > > + break;
>> > > + case 't':
>> > > + *s = '\x09';
>> > > + break;
>> > > + case '\\':
>> > > + *s = '\x5c';
>> >
>> > what's wrong with '\n' etc here?
>>
>> I am not sure what you mean. My interpretations:
>>
>
> i mean instead of *s='\x0a' you can write *s='\n' and it's clearer
> same for '\t' and '\\'

You are right. I forgot that C does provide some convenience for a
programmer... I will change it.


>> a cold so that has to wait...). I noticed that it uses the threadsafe
>> version of the mbtowc function. Do you think that is advisable in
>> general?
>
> the point of mbrtowc is not to be thread-safe but to be able to
> restart the decoding (it records the decoding state)

I see. Thanks for clearing that up.


> so you can feed a buffer into mbrtowc by looping until the end
> and continue later even if the buffer ended in the middle of a
> character sequence (or you can use it to decode the input one
> char at a time)
>
> mbtowc reports an error on an incomplete sequence and you don't
> know if it's an illegal sequence or you just need more input
> (not a problem if you have all input in one buffer)

I will check whether that could be a problem in the case of this tr
implementation (I still have some difficulties wrapping my head around
the buffer handling details of afgets).
Received on Thu Jan 16 2014 - 11:31:10 CET

This archive was generated by hypermail 2.3.0 : Thu Jan 16 2014 - 11:36:06 CET