f90getopt icon indicating copy to clipboard operation
f90getopt copied to clipboard

Function request

Open ougx opened this issue 3 years ago • 2 comments

Hi this is a great addon for Fortran programmer. I am hoping it can be even further enhanced/

  1. allow multiple arguments after a switch: myapp --range 1.0 2.0 or myapp -r 1.0 2.0 This can be achieved by adding another parameter in the option_s struct such as nopts. Default can be nopts == 0 for no argument.
  2. allow repeating switch: myapp --add file1 --add file2 and provide the occurrence of add

Are these implemented? If not, can you implement them? If you do not have time, I can help implement these through a pull request.

Thank you so much!

ougx avatar Mar 17 '23 14:03 ougx

some thing very interesting:

using ifort on windows, it will stop after paring the first option using the example

however, it runs fine, if you change the sample by calling the function outside the case selection. gfortran does not have this issue.

    do
        a = getopt("ab:h", opts)
        select case(a)
            case(char(0)) ! When all options are processed
                exit
            case("a")
                print*, "option alpha/a"
            case("b")
                print*, "option beta/b=",  trim(optarg) ! "trim" is quite useful to avoid trailing blanks
            case("h")
                print*, "help-screen"
        end select
    end do

ougx avatar Mar 17 '23 16:03 ougx

Are these implemented? If not, can you implement them?

No, not at the moment.

"I can help implement these through a pull request."

Feel free to do so. Thanks, Hani

haniibrahim avatar Mar 17 '23 20:03 haniibrahim