gtool5 Fortran 90/95 Library 1.0.0-rc5
日本語
Loading...
Searching...
No Matches
dc_args::option Interface Reference

Public Member Functions

subroutine dcargsoption0 (arg, options, flag, value, help)

Detailed Description

Definition at line 334 of file dc_args.f90.

Member Function/Subroutine Documentation

◆ dcargsoption0()

subroutine dc_args::option::dcargsoption0 ( type(args), intent(inout) arg,
character(len = *), dimension(:), intent(in) options,
logical, intent(out) flag,
character(len = *), intent(out), optional value,
character(len = *), intent(in), optional help )

Configure for getting command line option

Registers and retrieves option information.

Among command line arguments, retrieves information about options given in options to flag and value. If options is given in command line arguments, .true. is returned to flag, otherwise .false. is returned. If the option has a value specified, that value is returned to value. If the option itself is not given, an empty string is returned to value.

help registers a help message about options in arg. This message is output when using subroutine DCArgsHelp. The message changes depending on whether value is given.

Option Format

Among command line arguments, the following are judged as options:

  • When the first character is '-'. In this case it becomes a short option, and only one character after '-' is valid as the option.
  • When the first two characters are '–' (two hyphens). In this case it becomes a long option, and the string after '–' is valid as the option.

The option value is the string after "=".

Parameters
[in,out]argARGS derived type variable
[in]optionsArray of option names (e.g., '-s', '–size')
[out]flagReturns .true. if option is found
[out]valueReturns option value if specified (optional)
[in]helpHelp message for this option (optional)

Definition at line 558 of file dc_args.f90.

559 use dc_message, only: messagenotify
560 implicit none
561 type(ARGS), intent(inout) :: arg
562 character(len = *), intent(in) :: options(:)
563 logical, intent(out) :: flag
564 character(len = *), intent(out), optional :: value
565 character(len = *), intent(in), optional :: help
566 integer :: i, j, options_size, table_size
567 type(OPT_ENTRY), allocatable :: local_tables(:)
568 character(len = STRING) :: opt_name, opt_value, opt_full
569 character(len = *), parameter :: subname = 'DCArgsOption'
570 continue
571 flag = .false.
572 if (present(value)) value = ''
573 if (.not. arg % initialized) then
574 call messagenotify('W', subname, 'Call Open before Option in dc_args.')
575 call dcargsopen(arg)
576 end if
577 options_size = size(options)
578 if (options_size < 1) then
579 return
580 end if
581
582 !-----------------------------------
583 ! 構造体 ARGS へのヘルプメッセージ用の情報登録
584 ! * まずはテーブル arg % opt_table を一つ広げる.
585 !-----------------------------------
586 if ( .not. associated( arg % opt_table ) ) then
587 ! 1 つめのオプション指定
588 !
589 table_size = 0
590 allocate(arg % opt_table(table_size + 1))
591 else
592 ! 2 つめ以降のオプション指定
593 !
594 table_size = size(arg % opt_table)
595 allocate(local_tables(table_size))
596 local_tables(1:table_size) = arg % opt_table(1:table_size)
597 deallocate(arg % opt_table)
598 allocate(arg % opt_table(table_size + 1))
599 arg % opt_table(1:table_size) = local_tables(1:table_size)
600 deallocate(local_tables)
601 end if
602
603 !----- 値の代入 -----
604 allocate(arg % opt_table(table_size + 1) % options(options_size))
605 arg % opt_table(table_size + 1) % options = options
606 arg % opt_table(table_size + 1) % help_message = ''
607 if (present(help)) then
608 arg % opt_table(table_size + 1) % help_message = help
609 end if
610 arg % opt_table(table_size + 1) % optvalue_flag = present(value)
611
612
613 !----- options の正規化 -----
614 do i = 1, options_size
615 opt_full = arg % opt_table(table_size + 1) % options(i)
616 if (dcoptionformc(opt_full, opt_name, opt_value)) then
617 arg % opt_table(table_size + 1) % options(i) = opt_name
618 else
619 if (len(trim(adjustl(opt_full))) < 2) then
620 arg % opt_table(table_size + 1) % options(i) = &
621 & '-' // trim(adjustl(opt_full))
622 else
623 arg % opt_table(table_size + 1) % options(i) = &
624 & '--' // trim(adjustl(opt_full))
625 end if
626 end if
627 end do
628
629 ! arg % cmd_opts_list 内の探査と flag, value への代入
630 ! 呼ばれたものに関しては arg % cmd_opts_list % flag_called を
631 ! .true. に
632 do i = 1, options_size
633 do j = 1, size(arg % cmd_opts_list)
634 if (trim(arg % opt_table(table_size + 1) % options(i)) &
635 & == trim(arg % cmd_opts_list(j) % name)) then
636 flag = .true.
637 if (present(value)) then
638 value = arg % cmd_opts_list(j) % value
639 end if
640 arg % cmd_opts_list(j) % flag_called = .true.
641 end if
642 end do
643 end do
Message output module.

The documentation for this interface was generated from the following file: