gtool5 Fortran 90/95 ライブラリ 1.0.0-rc5
English
Loading...
Searching...
No Matches
dc_args::dcargsoption Interface Reference

Public Member Functions

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

Detailed Description

Definition at line 291 of file dc_args.f90.

Member Function/Subroutine Documentation

◆ dcargsoption0()

subroutine dc_args::dcargsoption::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 )

コマンドライン引数オプションを取得するための設定

オプション情報の登録と取得を行います.

コマンドライン引数のうち, options に与えるオプションに関する情 報を flagvalue に取得します. options がコマンドライン 引数に与えられていれば flag.true. が, そうでない場合は .false. が返ります. オプションに値が指定される場合は value に その値が返ります. オプション自体が与えられていない場合には value には空文字が返ります.

help には options に関するヘルプメッセージを arg に 登録します. サブルーチン DCArgsHelp を 用いた際に, このメッセージが出力されます. value を与えているかどうでこのメッセージは変化します.

オプションの書式

コマンドライン引数のうち, オプションと判定されるのは以下の場合です.

  • 1 文字目が '-' の場合. この場合は短いオプションとなり, '-' の次の一文字のみがオプションとして有効になります.
  • 1-2文字目が '–' (ハイフン 2 文字) の場合. この場合は長いオプションとなり, '–' 以降の文字列がオプションとして有効になります.

オプションの値は, "=" よりも後ろの文字列になります.

Parameters
[in,out]argARGS 型変数
[in]optionsオプション名の配列 (例: '-s', '–size')
[out]flagオプションが見つかった場合に .true. を返す
[out]valueオプション値が指定されている場合にその値を返す (省略可能)
[in]helpこのオプションのヘルプメッセージ (省略可能)

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
メッセージの出力

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