Loading...
Searching...
No Matches
Public Member Functions | List of all members
dc_args::dcargsoption Interface Reference

Public Member Functions

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

Detailed Description

Definition at line 235 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 
)

Definition at line 394 of file dc_args.f90.

395 !
396 ! オプション情報の登録と取得を行います.
397 !
398 ! コマンドライン引数のうち, *options* に与えるオプションに関する情
399 ! 報を *flag* と *value* に取得します. *options* がコマンドライン
400 ! 引数に与えられていれば *flag* に .true. が, そうでない場合は
401 ! .false. が返ります. オプションに値が指定される場合は *value* に
402 ! その値が返ります. オプション自体が与えられていない場合には
403 ! *value* には空文字が返ります.
404 !
405 ! *help* には *options* に関するヘルプメッセージを *arg* に
406 ! 登録します. サブルーチン DCArgsHelp を
407 ! 用いた際に, このメッセージが出力されます.
408 ! *value* を与えているかどうかでこのメッセージは変化します.
409 !
410 !=== オプションの書式
411 !
412 ! コマンドライン引数のうち, オプションと判定されるのは以下の場合です.
413 !
414 ! * 1 文字目が '-' の場合. この場合は短いオプションとなり, '-'
415 ! の次の一文字のみがオプションとして有効になります.
416 !
417 ! * 1-2文字目が '--' (ハイフン 2 文字) の場合.
418 ! この場合は長いオプションとなり,
419 ! '--' 以降の文字列がオプションとして有効になります.
420 !
421 ! オプションの値は, "=" よりも後ろの文字列になります.
422 !
423 ! 例
424 !
425 ! <b>コマンドライン引数</b> :: <b>オプション名, 値 </b>
426 ! -h :: -h, 無し
427 ! --help :: --help, 無し
428 ! -D=6 :: -D, 6
429 ! -debug= :: -d, 無し
430 ! --include=/usr :: --include, /usr
431 !
432
433 use dc_message, only: messagenotify
434 implicit none
435 type(ARGS), intent(inout) :: arg
436 character(len = *), intent(in) :: options(:)
437 logical, intent(out) :: flag
438 character(len = *), intent(out), optional :: value
439 character(len = *), intent(in), optional :: help
440 integer :: i, j, options_size, table_size
441 type(OPT_ENTRY), allocatable :: local_tables(:)
442 character(len = STRING) :: opt_name, opt_value, opt_full
443 character(len = *), parameter :: subname = 'DCArgsOption'
444 continue
445 flag = .false.
446 if (present(value)) value = ''
447 if (.not. arg % initialized) then
448 call messagenotify('W', subname, 'Call Open before Option in dc_args.')
449 call dcargsopen(arg)
450 end if
451 options_size = size(options)
452 if (options_size < 1) then
453 return
454 end if
455
456 !-----------------------------------
457 ! 構造体 ARGS へのヘルプメッセージ用の情報登録
458 ! * まずはテーブル arg % opt_table を一つ広げる.
459 !-----------------------------------
460 if ( .not. associated( arg % opt_table ) ) then
461 ! 1 つめのオプション指定
462 !
463 table_size = 0
464 allocate(arg % opt_table(table_size + 1))
465 else
466 ! 2 つめ以降のオプション指定
467 !
468 table_size = size(arg % opt_table)
469 allocate(local_tables(table_size))
470 local_tables(1:table_size) = arg % opt_table(1:table_size)
471 deallocate(arg % opt_table)
472 allocate(arg % opt_table(table_size + 1))
473 arg % opt_table(1:table_size) = local_tables(1:table_size)
474 deallocate(local_tables)
475 end if
476
477 !----- 値の代入 -----
478 allocate(arg % opt_table(table_size + 1) % options(options_size))
479 arg % opt_table(table_size + 1) % options = options
480 arg % opt_table(table_size + 1) % help_message = ''
481 if (present(help)) then
482 arg % opt_table(table_size + 1) % help_message = help
483 end if
484 arg % opt_table(table_size + 1) % optvalue_flag = present(value)
485
486
487 !----- options の正規化 -----
488 do i = 1, options_size
489 opt_full = arg % opt_table(table_size + 1) % options(i)
490 if (dcoptionformc(opt_full, opt_name, opt_value)) then
491 arg % opt_table(table_size + 1) % options(i) = opt_name
492 else
493 if (len(trim(adjustl(opt_full))) < 2) then
494 arg % opt_table(table_size + 1) % options(i) = &
495 & '-' // trim(adjustl(opt_full))
496 else
497 arg % opt_table(table_size + 1) % options(i) = &
498 & '--' // trim(adjustl(opt_full))
499 end if
500 end if
501 end do
502
503 ! arg % cmd_opts_list 内の探査と flag, value への代入
504 ! 呼ばれたものに関しては arg % cmd_opts_list % flag_called を
505 ! .true. に
506 do i = 1, options_size
507 do j = 1, size(arg % cmd_opts_list)
508 if (trim(arg % opt_table(table_size + 1) % options(i)) &
509 & == trim(arg % cmd_opts_list(j) % name)) then
510 flag = .true.
511 if (present(value)) then
512 value = arg % cmd_opts_list(j) % value
513 end if
514 arg % cmd_opts_list(j) % flag_called = .true.
515 end if
516 end do
517 end do

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