Skip to content

Commit

Permalink
Merge pull request 0382#1 from zoziha/update-1
Browse files Browse the repository at this point in the history
Add meson support
  • Loading branch information
0382 authored Feb 1, 2023
2 parents 738fad7 + 4ffa528 commit 1d64e5a
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 40 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ The simple way to use this package is copy the file `src/argparse-f.f90` into yo
argparse-f = { git="https://github.com/0382/argparse-f.git" }
```
In addition, `argparse-f` also supports the [Meson](https://mesonbuild.com/) build system.
## Parse rules
In this package, command line arguments are classified into two kinds: `option` and `argument`.
Expand Down
2 changes: 2 additions & 0 deletions README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ the output file is out.bin
argparse-f = { git="https://github.com/0382/argparse-f.git" }
```
此外,`argparse-f`也支持[Meson](https://mesonbuild.com/)构建系统。
## 解析规则
在我的库里面,命令行参数分为两大类(可选的选项,和必选的参数),每类又分为两种,总共四种命令行参数。
Expand Down
35 changes: 35 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
project(
'argparse-f',
'fortran',
version : '0.1.0',
license : 'MIT',
default_options : [
'buildtype=debugoptimized',
]
)

argparse_f_src = files(
'src/argparse-f.f90'
)

argparse_f_lib = library(
meson.project_name(),
sources : argparse_f_src,
version : meson.project_version(),
install : true,
)

argparse_f_inc = argparse_f_lib.private_dir_include()
argparse_f_dep = declare_dependency(
link_with : argparse_f_lib,
include_directories : argparse_f_inc,
)

test(
'argparse_f_check',
executable(
'argparse_f_check',
'test/check.f90',
dependencies : argparse_f_dep,
),
)
80 changes: 40 additions & 40 deletions src/argparse-f.f90
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ end subroutine sc_option_callback

contains

function make_argparser(description) result(this)
character(len=*) :: description
pure function make_argparser(description) result(this)
character(len=*), intent(in) :: description
type(argparser) :: this
this%description = description
this%program_name = ''
Expand All @@ -130,7 +130,7 @@ function make_argparser(description) result(this)
allocate (this%arguments(1))
end function make_argparser

subroutine deallocate_argparser(this)
pure subroutine deallocate_argparser(this)
type(argparser), intent(inout) :: this
if (allocated(this%sc_options)) deallocate (this%sc_options)
if (allocated(this%options)) deallocate (this%options)
Expand Down Expand Up @@ -501,7 +501,7 @@ subroutine argp_print_as_ini(this, unit, comment)
subroutine argp_add_sc_option(this, short_name, long_name, help, callback)
class(argparser), intent(inout) :: this
character(len=*), intent(in) :: short_name, long_name, help
external :: callback
procedure(sc_option_callback) :: callback
integer :: t_sc_size, idx
type(short_circuit_option), dimension(:), allocatable :: t_sc_opts
! long name must not be empty
Expand Down Expand Up @@ -545,7 +545,7 @@ subroutine argp_add_help_option(this)
! end subroutine local_print_help
end subroutine argp_add_help_option

subroutine argp_try_add_option(this, short_name, long_name, help)
pure subroutine argp_try_add_option(this, short_name, long_name, help)
class(argparser), intent(inout) :: this
character(len=*), intent(in) :: short_name, long_name, help
integer :: t_opt_size, idx
Expand Down Expand Up @@ -573,7 +573,7 @@ subroutine argp_try_add_option(this, short_name, long_name, help)
this%options(idx)%help = help
end subroutine argp_try_add_option

subroutine argp_add_option_logical(this, short_name, long_name, help)
pure subroutine argp_add_option_logical(this, short_name, long_name, help)
class(argparser), intent(inout) :: this
character(len=*), intent(in) :: short_name, long_name, help
integer :: idx
Expand All @@ -583,7 +583,7 @@ subroutine argp_add_option_logical(this, short_name, long_name, help)
this%options(idx)%value = "F"
end subroutine argp_add_option_logical

subroutine argp_add_option_integer(this, short_name, long_name, help, default)
pure subroutine argp_add_option_integer(this, short_name, long_name, help, default)
class(argparser), intent(inout) :: this
character(len=*), intent(in) :: short_name, long_name, help
integer, intent(in) :: default
Expand All @@ -596,7 +596,7 @@ subroutine argp_add_option_integer(this, short_name, long_name, help, default)
this%options(idx)%value = adjustl(value_buffer)
end subroutine argp_add_option_integer

subroutine argp_add_option_real(this, short_name, long_name, help, default)
pure subroutine argp_add_option_real(this, short_name, long_name, help, default)
class(argparser), intent(inout) :: this
character(len=*), intent(in) :: short_name, long_name, help
real, intent(in) :: default
Expand All @@ -609,7 +609,7 @@ subroutine argp_add_option_real(this, short_name, long_name, help, default)
this%options(idx)%value = adjustl(value_buffer)
end subroutine argp_add_option_real

subroutine argp_add_option_double(this, short_name, long_name, help, default)
pure subroutine argp_add_option_double(this, short_name, long_name, help, default)
class(argparser), intent(inout) :: this
character(len=*), intent(in) :: short_name, long_name, help
real(kind=8), intent(in) :: default
Expand All @@ -622,7 +622,7 @@ subroutine argp_add_option_double(this, short_name, long_name, help, default)
this%options(idx)%value = adjustl(value_buffer)
end subroutine argp_add_option_double

subroutine argp_add_option_string(this, short_name, long_name, help, default)
pure subroutine argp_add_option_string(this, short_name, long_name, help, default)
class(argparser), intent(inout) :: this
character(len=*), intent(in) :: short_name, long_name, help
character(len=*), intent(in) :: default
Expand All @@ -635,7 +635,7 @@ subroutine argp_add_option_string(this, short_name, long_name, help, default)
this%options(idx)%value = adjustl(value_buffer)
end subroutine argp_add_option_string

subroutine argp_try_add_argument(this, name, help)
pure subroutine argp_try_add_argument(this, name, help)
class(argparser), intent(inout) :: this
character(len=*), intent(in) :: name, help
integer :: t_arg_size, idx
Expand All @@ -657,7 +657,7 @@ subroutine argp_try_add_argument(this, name, help)
this%arguments(idx)%help = help
end subroutine argp_try_add_argument

subroutine argp_try_add_named_argument(this, name, help)
pure subroutine argp_try_add_named_argument(this, name, help)
class(argparser), intent(inout) :: this
character(len=*), intent(in) :: name, help
integer :: t_arg_size, idx
Expand All @@ -679,7 +679,7 @@ subroutine argp_try_add_named_argument(this, name, help)
this%named_arguments(idx)%help = help
end subroutine argp_try_add_named_argument

subroutine argp_add_argument_integer(this, name, help)
pure subroutine argp_add_argument_integer(this, name, help)
class(argparser), intent(inout) :: this
character(len=*), intent(in) :: name, help
integer :: idx
Expand All @@ -688,7 +688,7 @@ subroutine argp_add_argument_integer(this, name, help)
this%arguments(idx)%value_type = "integer"
end subroutine argp_add_argument_integer

subroutine argp_add_argument_real(this, name, help)
pure subroutine argp_add_argument_real(this, name, help)
class(argparser), intent(inout) :: this
character(len=*), intent(in) :: name, help
integer :: idx
Expand All @@ -697,7 +697,7 @@ subroutine argp_add_argument_real(this, name, help)
this%arguments(idx)%value_type = "real"
end subroutine argp_add_argument_real

subroutine argp_add_argument_double(this, name, help)
pure subroutine argp_add_argument_double(this, name, help)
class(argparser), intent(inout) :: this
character(len=*), intent(in) :: name, help
integer :: idx
Expand All @@ -706,7 +706,7 @@ subroutine argp_add_argument_double(this, name, help)
this%arguments(idx)%value_type = "double"
end subroutine argp_add_argument_double

subroutine argp_add_argument_string(this, name, help)
pure subroutine argp_add_argument_string(this, name, help)
class(argparser), intent(inout) :: this
character(len=*), intent(in) :: name, help
integer :: idx
Expand All @@ -715,7 +715,7 @@ subroutine argp_add_argument_string(this, name, help)
this%arguments(idx)%value_type = "string"
end subroutine argp_add_argument_string

subroutine argp_add_named_argument_integer(this, name, help)
pure subroutine argp_add_named_argument_integer(this, name, help)
class(argparser), intent(inout) :: this
character(len=*), intent(in) :: name, help
integer :: idx
Expand All @@ -724,7 +724,7 @@ subroutine argp_add_named_argument_integer(this, name, help)
this%named_arguments(idx)%value_type = "integer"
end subroutine argp_add_named_argument_integer

subroutine argp_add_named_argument_real(this, name, help)
pure subroutine argp_add_named_argument_real(this, name, help)
class(argparser), intent(inout) :: this
character(len=*), intent(in) :: name, help
integer :: idx
Expand All @@ -733,7 +733,7 @@ subroutine argp_add_named_argument_real(this, name, help)
this%named_arguments(idx)%value_type = "real"
end subroutine argp_add_named_argument_real

subroutine argp_add_named_argument_double(this, name, help)
pure subroutine argp_add_named_argument_double(this, name, help)
class(argparser), intent(inout) :: this
character(len=*), intent(in) :: name, help
integer :: idx
Expand All @@ -742,7 +742,7 @@ subroutine argp_add_named_argument_double(this, name, help)
this%named_arguments(idx)%value_type = "double"
end subroutine argp_add_named_argument_double

subroutine argp_add_named_argument_string(this, name, help)
pure subroutine argp_add_named_argument_string(this, name, help)
class(argparser), intent(inout) :: this
character(len=*), intent(in) :: name, help
integer :: idx
Expand All @@ -751,7 +751,7 @@ subroutine argp_add_named_argument_string(this, name, help)
this%named_arguments(idx)%value_type = "string"
end subroutine argp_add_named_argument_string

integer function argp_find_option(this, name) result(ans)
pure integer function argp_find_option(this, name) result(ans)
class(argparser), intent(in) :: this
character(len=*), intent(in) :: name
integer :: i
Expand All @@ -764,7 +764,7 @@ integer function argp_find_option(this, name) result(ans)
error stop "(get error) option not found: "//trim(name)
end function argp_find_option

subroutine argp_check_option_type(this, idx, type)
pure subroutine argp_check_option_type(this, idx, type)
class(argparser), intent(in) :: this
integer, intent(in) :: idx
character(len=*), intent(in) :: type
Expand All @@ -774,7 +774,7 @@ subroutine argp_check_option_type(this, idx, type)
end if
end subroutine argp_check_option_type

logical function argp_get_option_logical(this, name) result(ans)
pure logical function argp_get_option_logical(this, name) result(ans)
class(argparser), intent(in) :: this
character(len=*), intent(in) :: name
integer :: i
Expand All @@ -783,13 +783,13 @@ logical function argp_get_option_logical(this, name) result(ans)
read (unit=this%options(i)%value, fmt=*) ans
end function argp_get_option_logical

logical function argp_has_option(this, name) result(ans)
pure logical function argp_has_option(this, name) result(ans)
class(argparser), intent(in) :: this
character(len=*), intent(in) :: name
ans = argp_get_option_logical(this, name)
end function argp_has_option

integer function argp_get_option_integer(this, name) result(ans)
pure integer function argp_get_option_integer(this, name) result(ans)
class(argparser), intent(in) :: this
character(len=*), intent(in) :: name
integer :: i
Expand All @@ -798,7 +798,7 @@ integer function argp_get_option_integer(this, name) result(ans)
read (unit=this%options(i)%value, fmt=*) ans
end function argp_get_option_integer

real function argp_get_option_real(this, name) result(ans)
pure real function argp_get_option_real(this, name) result(ans)
class(argparser), intent(in) :: this
character(len=*), intent(in) :: name
integer :: i
Expand All @@ -807,7 +807,7 @@ real function argp_get_option_real(this, name) result(ans)
read (unit=this%options(i)%value, fmt=*) ans
end function argp_get_option_real

real(kind=8) function argp_get_option_double(this, name) result(ans)
pure real(kind=8) function argp_get_option_double(this, name) result(ans)
class(argparser), intent(in) :: this
character(len=*), intent(in) :: name
integer :: i
Expand All @@ -816,7 +816,7 @@ real(kind=8) function argp_get_option_double(this, name) result(ans)
read (unit=this%options(i)%value, fmt=*) ans
end function argp_get_option_double

function argp_get_option_string(this, name) result(ans)
pure function argp_get_option_string(this, name) result(ans)
class(argparser), intent(in) :: this
character(len=*), intent(in) :: name
character(len=value_len) :: ans
Expand All @@ -826,7 +826,7 @@ function argp_get_option_string(this, name) result(ans)
ans = this%options(i)%value
end function argp_get_option_string

integer function argp_find_argument(this, name) result(ans)
pure integer function argp_find_argument(this, name) result(ans)
class(argparser), intent(in) :: this
character(len=*), intent(in) :: name
integer :: i
Expand All @@ -845,7 +845,7 @@ integer function argp_find_argument(this, name) result(ans)
error stop "(get error) argument not found: "//trim(name)
end function argp_find_argument

subroutine argp_check_argument_type(this, idx, type)
pure subroutine argp_check_argument_type(this, idx, type)
class(argparser), intent(in) :: this
integer, intent(in) :: idx
character(len=*), intent(in) :: type
Expand All @@ -863,7 +863,7 @@ subroutine argp_check_argument_type(this, idx, type)
end if
end subroutine argp_check_argument_type

integer function argp_get_argument_integer(this, name) result(ans)
pure integer function argp_get_argument_integer(this, name) result(ans)
class(argparser), intent(in) :: this
character(len=*), intent(in) :: name
integer :: i
Expand All @@ -876,7 +876,7 @@ integer function argp_get_argument_integer(this, name) result(ans)
end if
end function argp_get_argument_integer

real function argp_get_argument_real(this, name) result(ans)
pure real function argp_get_argument_real(this, name) result(ans)
class(argparser), intent(in) :: this
character(len=*), intent(in) :: name
integer :: i
Expand All @@ -889,7 +889,7 @@ real function argp_get_argument_real(this, name) result(ans)
end if
end function argp_get_argument_real

real(kind=8) function argp_get_argument_double(this, name) result(ans)
pure real(kind=8) function argp_get_argument_double(this, name) result(ans)
class(argparser), intent(in) :: this
character(len=*), intent(in) :: name
integer :: i
Expand All @@ -902,7 +902,7 @@ real(kind=8) function argp_get_argument_double(this, name) result(ans)
end if
end function argp_get_argument_double

function argp_get_argument_string(this, name) result(ans)
pure function argp_get_argument_string(this, name) result(ans)
class(argparser), intent(in) :: this
character(len=*), intent(in) :: name
character(len=value_len) :: ans
Expand All @@ -916,7 +916,7 @@ function argp_get_argument_string(this, name) result(ans)
end if
end function argp_get_argument_string

subroutine argp_check_short_name(this, name)
pure subroutine argp_check_short_name(this, name)
class(argparser), intent(in) :: this
character(len=*), intent(in) :: name
integer :: name_size, char_pos
Expand All @@ -930,9 +930,9 @@ subroutine argp_check_short_name(this, name)
end if
end subroutine argp_check_short_name

subroutine argp_check_long_name(this, name)
pure subroutine argp_check_long_name(this, name)
class(argparser), intent(in) :: this
character(len=*) :: name
character(len=*), intent(in) :: name
integer :: i
if (name == "") then
error stop "(build error) long option name cannot be empty"
Expand All @@ -952,9 +952,9 @@ subroutine argp_check_long_name(this, name)
end do
end subroutine argp_check_long_name

subroutine argp_check_argument_name(this, name)
pure subroutine argp_check_argument_name(this, name)
class(argparser), intent(in) :: this
character(len=*) :: name
character(len=*), intent(in) :: name
integer :: i
if (name == "") then
error stop "(build error) argument name cannot be empty"
Expand All @@ -971,7 +971,7 @@ subroutine argp_check_argument_name(this, name)
end do
end subroutine argp_check_argument_name

subroutine split(line, sep, result)
pure subroutine split(line, sep, result)
character(len=*), intent(in) :: line
character(len=*), intent(in) :: sep
character(len=*), dimension(:), allocatable, intent(out) :: result
Expand Down

0 comments on commit 1d64e5a

Please sign in to comment.