92 character(len=80):: optarg
95 logical:: opterr=.true.
98 character(len=80) :: name
104 integer,
private:: grpind=2
119 character(len=*),
intent(in):: str
120 integer,
intent(in):: i, j
122 if ( 1 <= i .and. i <= j .and. j <= len(str))
then
131 character function getopt( optstring, longopts )
133 character(len=*),
intent(in):: optstring
134 type(option_s),
intent(in),
optional:: longopts(:)
137 character(len=80):: arg
140 if ( optind > iargc())
then
144 call getarg( optind, arg )
145 if ( present( longopts ) .and. arg(1:2) ==
'--' )
then
147 elseif ( arg(1:1) ==
'-' )
then
158 type(option_s),
intent(in):: longopts(:)
159 character(len=*),
intent(in):: arg
166 do i = 1,
size(longopts)
167 if ( arg(3:) == longopts(i)%name )
then
168 optopt = longopts(i)%val
170 if ( longopts(i)%has_arg )
then
171 if ( optind <= iargc())
then
172 call getarg( optind, optarg )
174 elseif ( opterr )
then
175 print
'(a,a,a)',
"Error: option '", trim(arg),
"' requires an argument"
184 print
'(a,a,a)',
"Error: unrecognized option '", trim(arg),
"'"
192 character(len=*),
intent(in):: optstring, arg
197 arglen = len( trim( arg ))
198 optopt = arg(grpind:grpind)
201 i = index( optstring, optopt )
206 print
'(a,a,a)',
"Error: unrecognized option '-", optopt,
"'"
209 if ( i > 0 .and.
substr( optstring, i+1, i+1 ) ==
':' )
then
212 if ( arglen > grpind )
then
214 optarg = arg(grpind+1:arglen)
215 elseif ( optind <= iargc())
then
217 call getarg( optind, optarg )
219 elseif ( opterr )
then
220 print
'(a,a,a)',
"Error: option '-", optopt,
"' requires an argument"
223 elseif ( arglen > grpind )
then
character function getopt(optstring, longopts)
character function process_short(optstring, arg)
character function process_long(longopts, arg)
character function substr(str, i, j)