Re: [Toybox] Defect in Argument parsing for "#" and "-"

2012-07-04 Thread Rob Landley
On 07/03/2012 11:49 PM, Ashwini Sharma wrote:
>> I can grab a third character (maybe %) for literal long. The tradeoff
>> here is between generic behavior (which can share code) and precise
>> behavior that does exactly what you want. Some things need suffixes, so
>> I made everything accept suffixes by default because I didn't see the
>> harm. Apparently you do. Could you explain the harm to me?
> 
>  I was looking at this from the perspective where I do not want any
> alpha chars for the argument, not even Suffixes. Else I don't see any
> harm in it.

The user is never _required_ to supply alpha characters, and if they do
so anywhere but the very end it'll barf.

It does impose a format.  If you go "32kk" it'll barf, same with "3k2".
(I can fix treating an empty string as zero that was an oversight.)

So if I implement a '%' arg type, it this will add extra code for a mode
that does less. It wouldn't elimiate the old '#' mode that accepts
suffixes, because some commands are required to accept suffixes (for dd
and truncate it's apparently a gnuism but split -b has it in posix.)

It's possible this is the correct thing to do anyway, but that implies
gnu was wrong to add it to dd if posix didn't specify. My theory was
"since I already wrote the code, it doesn't cost extra to use it, and
consistent behavior is good". I'm open to counter-examples...

Rob
-- 
GNU/Linux isn't: Linux=GPLv2, GNU=GPLv3+, they can't share code.
Either it's "mere aggregation", or a license violation.  Pick one.
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


Re: [Toybox] Defect in Argument parsing for "#" and "-"

2012-07-03 Thread Ashwini Sharma
On 7/4/12, Rob Landley  wrote:
> On 07/02/2012 10:05 PM, Ashwini Sharma wrote:
>> Hi Rob,
>>
>>  I was using '#' for accepting a integer parameter. As per the parsing
>> logic
>> you used function atolx(), for converting the string to long. This
>> function assumes suffixes with the supplied string. There are
>> possibilities that user may not want suffixes to be there, i.e. any
>> alpha char in the argument should be treated as "Invalid Argument".
>>
>> Also for the cases where user has only supplied a suffix, without any
>> number, atolx will return 0, which may not be the desired case.
>>
>> I had a case where depth of traversal was to be defined as cmdline
>> argument.
>> Giving "kmgtpe" would return zero, whereas I wanted it to only
>> integers as argument and no alpha characters.
>
> Understood.  Question: why?
>
>> Hence I am of the opinion that,
>>
>>   1. It should be treated as "Invalid Argument" if no number is specified
>> And
>>   2. It should be configurable, if a feature wants the suffixes to be
>> handled or not.
>>
>> Please do provide your opinion.
>
> I can grab a third character (maybe %) for literal long. The tradeoff
> here is between generic behavior (which can share code) and precise
> behavior that does exactly what you want. Some things need suffixes, so
> I made everything accept suffixes by default because I didn't see the
> harm. Apparently you do. Could you explain the harm to me?

 I was looking at this from the perspective where I do not want any
alpha chars for the argument, not even Suffixes. Else I don't see any
harm in it.

>
> (It's not that much extra code, but it's extra code you can't configure
> out because it's in the generic code shared by all commands...)
>
> Thanks,
>
> Rob
> --
> GNU/Linux isn't: Linux=GPLv2, GNU=GPLv3+, they can't share code.
> Either it's "mere aggregation", or a license violation.  Pick one.
>
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


Re: [Toybox] Defect in Argument parsing for "#" and "-"

2012-07-03 Thread Rob Landley
On 07/02/2012 10:05 PM, Ashwini Sharma wrote:
> I had a case where depth of traversal was to be defined as cmdline argument.
> Giving "kmgtpe" would return zero, whereas I wanted it to only
> integers as argument and no alpha characters.

By the way, that probably _is_ a bug. If you haven't seen a digit yet,
units are useless. I'd have to check what "sleep" and "od" and such
wanted in that case, but I can probably fix it so you need at least
_something_ before a unit. (Of course that opens "- -k" and such, which
depends on what strtol() does with just a minus...)

Rob
-- 
GNU/Linux isn't: Linux=GPLv2, GNU=GPLv3+, they can't share code.
Either it's "mere aggregation", or a license violation.  Pick one.
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


Re: [Toybox] Defect in Argument parsing for "#" and "-"

2012-07-03 Thread Rob Landley
On 07/02/2012 10:05 PM, Ashwini Sharma wrote:
> Hi Rob,
> 
>  I was using '#' for accepting a integer parameter. As per the parsing logic
> you used function atolx(), for converting the string to long. This
> function assumes suffixes with the supplied string. There are
> possibilities that user may not want suffixes to be there, i.e. any
> alpha char in the argument should be treated as "Invalid Argument".
> 
> Also for the cases where user has only supplied a suffix, without any
> number, atolx will return 0, which may not be the desired case.
> 
> I had a case where depth of traversal was to be defined as cmdline argument.
> Giving "kmgtpe" would return zero, whereas I wanted it to only
> integers as argument and no alpha characters.

Understood.  Question: why?

> Hence I am of the opinion that,
> 
>   1. It should be treated as "Invalid Argument" if no number is specified And
>   2. It should be configurable, if a feature wants the suffixes to be
> handled or not.
> 
> Please do provide your opinion.

I can grab a third character (maybe %) for literal long. The tradeoff
here is between generic behavior (which can share code) and precise
behavior that does exactly what you want. Some things need suffixes, so
I made everything accept suffixes by default because I didn't see the
harm. Apparently you do. Could you explain the harm to me?

(It's not that much extra code, but it's extra code you can't configure
out because it's in the generic code shared by all commands...)

Thanks,

Rob
-- 
GNU/Linux isn't: Linux=GPLv2, GNU=GPLv3+, they can't share code.
Either it's "mere aggregation", or a license violation.  Pick one.
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


[Toybox] Defect in Argument parsing for "#" and "-"

2012-07-02 Thread Ashwini Sharma
Hi Rob,

 I was using '#' for accepting a integer parameter. As per the parsing logic
you used function atolx(), for converting the string to long. This
function assumes suffixes with the supplied string. There are
possibilities that user may not want suffixes to be there, i.e. any
alpha char in the argument should be treated as "Invalid Argument".

Also for the cases where user has only supplied a suffix, without any
number, atolx will return 0, which may not be the desired case.

I had a case where depth of traversal was to be defined as cmdline argument.
Giving "kmgtpe" would return zero, whereas I wanted it to only
integers as argument and no alpha characters.

Hence I am of the opinion that,

  1. It should be treated as "Invalid Argument" if no number is specified And
  2. It should be configurable, if a feature wants the suffixes to be
handled or not.

Please do provide your opinion.

regards,
Ashwini
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net