On Fri, 28 Jun 2024 14:39:12 GMT, Sonia Zaldana Calles <szald...@openjdk.org> 
wrote:

>> Sonia Zaldana Calles has updated the pull request incrementally with three 
>> additional commits since the last revision:
>> 
>>  - Updating copyright header
>>  - Modifying usage to --help and -help. Updated ensuing test case to test 
>> both
>>  - Updating copyright headers
>
> One question. With the current implementation, this is the check in place to 
> offer help: 
> ```strncmp(args, " -help", 6) == 0 || strncmp(args, " --help", 7)```
> 
> I could change this to do `strncmp(args, " -h", 3)` instead but this is a bit 
> problematic as it would block any future flags that start out with `-h` from 
> working.
> 
> I've been giving this some thought on how to implement a restrictive way to 
> check only for the arguments `-h` or `-help` while also allowing for other 
> arguments to be passed afterwards that should be ignored. 
> 
> I thought about perhaps using some type of regex matching with 
> ```std:regex``` but hotspot doesn't allow the use of global operators new and 
> delete.  I don't want to overengineer this piece of logic so I was wondering 
> if there was a regex matching utility that I could leverage in HotSpot? 
> 
> The alternative would be to make the check more restrictive and not allow for 
> arguments after `-h` has been issued i.e. `strcmp(args, "-h") == 0`. 
> 
> Thanks for your help!

Hi @SoniaZaldana 

sorry for the delay, I'm snowed in atm.

> One question. With the current implementation, this is the check in place to 
> offer help: `strncmp(args, " -help", 6) == 0 || strncmp(args, " --help", 7)`
> 
> I could change this to do `strncmp(args, " -h", 3)` instead but this is a bit 
> problematic as it would block any future flags that start out with `-h` from 
> working.

Well, we restrict future compatibility no matter what we do. 

> 
> I've been giving this some thought on how to implement a restrictive way to 
> check only for the arguments `-h` or `-help` while also allowing for other 
> arguments to be passed afterwards that should be ignored.
> 
> I thought about perhaps using some type of regex matching with `std:regex` 
> but hotspot doesn't allow the use of global operators new and delete.

God no :)

> I don't want to overengineer this piece of logic so I was wondering if there 
> was a regex matching utility that I could leverage in HotSpot?

No need, you can do this with normal C tools.

with p pointing to start of arguments:
- forward p and walk all spaces, break out for \0 
- strncmp with "-h", size 2
- if follow-up char is either blank or \0, its a help command. If we agree to 
just ignore follow up arguments, you can now just rebuild the command as "help 
commandname".
- bonus for writing a warning if there are arguments after help

> 
> The alternative would be to make the check more restrictive and not allow for 
> arguments after `-h` has been issued i.e. `strcmp(args, "-h") == 0`.
> 
> Thanks for your help!

Cheers

-------------

PR Comment: https://git.openjdk.org/jdk/pull/19776#issuecomment-2202046212

Reply via email to