From 1075f02ec7c85e0b6af157c512550f754ae117e4 Mon Sep 17 00:00:00 2001 From: "John S. Urban" Date: Fri, 9 Jun 2023 23:55:59 -0400 Subject: [PATCH 1/4] document run(3f) and markdown errata --- src/fpm_filesystem.F90 | 83 +++++++++++++++++++++++++++++++++++------- src/fpm_strings.f90 | 18 ++++----- 2 files changed, 77 insertions(+), 24 deletions(-) diff --git a/src/fpm_filesystem.F90 b/src/fpm_filesystem.F90 index 97feb1801b..d5637357d1 100644 --- a/src/fpm_filesystem.F90 +++ b/src/fpm_filesystem.F90 @@ -774,31 +774,32 @@ subroutine filewrite(filename,filedata) end subroutine filewrite -function which(command) result(pathname) +!>AUTHOR: John S. Urban +!!LICENSE: Public Domain !> -!!##NAME +!!##Name !! which(3f) - [M_io:ENVIRONMENT] given a command name find the pathname by searching !! the directories in the environment variable $PATH !! (LICENSE:PD) !! -!!##SYNTAX +!!##Syntax !! function which(command) result(pathname) !! !! character(len=*),intent(in) :: command !! character(len=:),allocatable :: pathname !! -!!##DESCRIPTION +!!##Description !! Given a command name find the first file with that name in the directories !! specified by the environment variable $PATH. !! -!!##OPTIONS +!!##options !! COMMAND the command to search for !! -!!##RETURNS +!!##Returns !! PATHNAME the first pathname found in the current user path. Returns blank !! if the command is not found. !! -!!##EXAMPLE +!!##Example !! !! Sample program: !! @@ -812,11 +813,7 @@ function which(command) result(pathname) !! write(*,*)'install is ',which('install') !! end program demo_which !! -!!##AUTHOR -!! John S. Urban -!!##LICENSE -!! Public Domain - +function which(command) result(pathname) character(len=*),intent(in) :: command character(len=:),allocatable :: pathname, checkon, paths(:), exts(:) integer :: i, j @@ -854,8 +851,66 @@ function which(command) result(pathname) enddo SEARCH end function which -!> echo command string and pass it to the system for execution -!call run(cmd,echo=.false.,exitstat=exitstat,verbose=.false.,redirect='') +!>AUTHOR: fpm(1) contributors +!!LICENSE: MIT +!> +!!##Name +!! run(3f) - execute specified system command and selectively echo +!! command and output to a file and/or stdout. +!! (LICENSE:MIT) +!! +!!##Syntax +!! subroutine run(cmd,echo,exitstat,verbose,redirect) +!! +!! character(len=*), intent(in) :: cmd +!! logical,intent(in),optional :: echo +!! integer, intent(out),optional :: exitstat +!! logical, intent(in), optional :: verbose +!! character(*), intent(in), optional :: redirect +!! +!!##Description +!! Execute the specified system command. Optionally +!! +!! + echo the command before execution +!! + return the system exit status of the command. +!! + redirect the output of the command to a file. +!! + echo command output to stdout +!! +!! Calling run(3f) is preferred to direct calls to +!! execute_command_line(3f) in the fpm(1) source to provide a standard +!! interface where output modes can be specified. +!! +!!##Options +!! CMD System command to execute +!! ECHO Whether to echo the command being executed or not +!! Defaults to .TRUE. . +!! VERBOSE Whether to redirect the command output to a null device or not +!! Defaults to .TRUE. . +!! REDIRECT Filename to redirect stdout and stderr of the command into. +!! If generated it is closed before run(3f) returns. +!! EXITSTAT The system exit status of the command when supported by +!! the system. If not present and a non-zero status is +!! generated program termination occurs. +!! +!!##Example +!! +!! Sample program: +!! +!! Checking the error message and counting lines: +!! +!! program demo_run +!! use fpm_filesystem, only : run +!! implicit none +!! logical,parameter :: T=.true., F=.false. +!! integer :: exitstat +!! character(len=:),allocatable :: cmd +!! cmd='ls -ltrasd *.md' +!! call run(cmd) +!! call run(cmd,exitstat=exitstat) +!! call run(cmd,echo=F) +!! call run(cmd,verbose=F) +!! end program demo_run +!! subroutine run(cmd,echo,exitstat,verbose,redirect) character(len=*), intent(in) :: cmd logical,intent(in),optional :: echo diff --git a/src/fpm_strings.f90 b/src/fpm_strings.f90 index 404a7dc6f5..e478f4dba6 100644 --- a/src/fpm_strings.f90 +++ b/src/fpm_strings.f90 @@ -236,9 +236,9 @@ pure function fnv_1a_string_t(input, seed) result(hash) end function fnv_1a_string_t - !>Author: John S. Urban - !!License: Public Domain - !! Changes a string to lowercase over optional specified column range +!>Author: John S. Urban +!!License: Public Domain +!! Changes a string to lowercase over optional specified column range elemental pure function lower(str,begin,end) result (string) character(*), intent(In) :: str @@ -624,8 +624,9 @@ pure function join(str,sep,trm,left,right,start,end) result (string) if(present(end))string=string//end end function join -!>##AUTHOR John S. Urban -!!##LICENSE Public Domain +!>AUTHOR: John S. Urban +!!LICENSE: Public Domain +!> !!## NAME !! glob(3f) - [fpm_strings:COMPARE] compare given string for match to !! pattern which may contain wildcard characters @@ -1259,6 +1260,8 @@ subroutine remove_newline_characters(string) end subroutine remove_newline_characters +!>AUTHOR: John S. Urban +!!LICENSE: Public Domain !> !!### NAME !! notabs(3f) - [fpm_strings:NONALPHA] expand tab characters @@ -1316,11 +1319,6 @@ end subroutine remove_newline_characters !!### SEE ALSO !! GNU/Unix commands expand(1) and unexpand(1) !! -!!### AUTHOR -!! John S. Urban -!! -!!### LICENSE -!! Public Domain elemental impure subroutine notabs(instr,outstr,ilen) ! ident_31="@(#)fpm_strings::notabs(3f): convert tabs to spaces while maintaining columns, remove CRLF chars" From 2ada9fae44a8ed62cde35c636f79dbb81f2fa282 Mon Sep 17 00:00:00 2001 From: "John S. Urban" Date: Sat, 10 Jun 2023 00:00:23 -0400 Subject: [PATCH 2/4] start example directory --- example/demo_run.f90 | 47 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 example/demo_run.f90 diff --git a/example/demo_run.f90 b/example/demo_run.f90 new file mode 100644 index 0000000000..c22a145000 --- /dev/null +++ b/example/demo_run.f90 @@ -0,0 +1,47 @@ +program demo_run +use fpm_filesystem, only: run +implicit none +integer :: exitstat +character(len=:), allocatable :: cmd +logical, parameter T = .true., F = .false. +cmd = 'ls -ltrasd *.md' + + call run(cmd) + call paws('default options (ie. echo=T verbose=T)') + + call run(cmd, exitstat=exitstat) + write (*, *) 'exitstat=', exitstat + call paws('exitstat') + + call run(cmd, echo=F) + call paws('echo=F') + + call run(cmd, verbose=F) + call paws('verbose=F') + + call run(cmd, verbose=F, echo=F) + call paws('verbose=F echo=F') + + call run(cmd, redirect='_scratch') + call paws('redirect="_scratch"') + + call run(cmd, redirect='_scratch', verbose=F) + call paws('redirect="_scratch" verbose=F') + + call run(cmd, redirect='_scratch', verbose=T) + call paws('redirect="_scratch" verbose=T') + +contains + +subroutine paws(str) +character(len=*), intent(in) :: str +character(len=1) :: chr +integer :: iostat + + write (*, '(a,": ")', advance='no') str + read (*, '(a)', iostat=iostat) chr + write (*, '(a)') repeat('-', 60) + +end subroutine paws + +end program demo_run From 69edccf1ffb69186e077953dc57dd38b9694b52f Mon Sep 17 00:00:00 2001 From: "John S. Urban" Date: Sat, 10 Jun 2023 00:20:40 -0400 Subject: [PATCH 3/4] correct example --- example/demo_run.f90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/demo_run.f90 b/example/demo_run.f90 index c22a145000..90bebb9e32 100644 --- a/example/demo_run.f90 +++ b/example/demo_run.f90 @@ -3,7 +3,7 @@ program demo_run implicit none integer :: exitstat character(len=:), allocatable :: cmd -logical, parameter T = .true., F = .false. +logical, parameter :: T = .true., F = .false. cmd = 'ls -ltrasd *.md' call run(cmd) From 98eb02134fa42dedccd4404817bbb11464151268 Mon Sep 17 00:00:00 2001 From: "John S. Urban" Date: Sat, 10 Jun 2023 00:30:05 -0400 Subject: [PATCH 4/4] remove example/ --- example/demo_run.f90 | 47 -------------------------------------------- 1 file changed, 47 deletions(-) delete mode 100644 example/demo_run.f90 diff --git a/example/demo_run.f90 b/example/demo_run.f90 deleted file mode 100644 index 90bebb9e32..0000000000 --- a/example/demo_run.f90 +++ /dev/null @@ -1,47 +0,0 @@ -program demo_run -use fpm_filesystem, only: run -implicit none -integer :: exitstat -character(len=:), allocatable :: cmd -logical, parameter :: T = .true., F = .false. -cmd = 'ls -ltrasd *.md' - - call run(cmd) - call paws('default options (ie. echo=T verbose=T)') - - call run(cmd, exitstat=exitstat) - write (*, *) 'exitstat=', exitstat - call paws('exitstat') - - call run(cmd, echo=F) - call paws('echo=F') - - call run(cmd, verbose=F) - call paws('verbose=F') - - call run(cmd, verbose=F, echo=F) - call paws('verbose=F echo=F') - - call run(cmd, redirect='_scratch') - call paws('redirect="_scratch"') - - call run(cmd, redirect='_scratch', verbose=F) - call paws('redirect="_scratch" verbose=F') - - call run(cmd, redirect='_scratch', verbose=T) - call paws('redirect="_scratch" verbose=T') - -contains - -subroutine paws(str) -character(len=*), intent(in) :: str -character(len=1) :: chr -integer :: iostat - - write (*, '(a,": ")', advance='no') str - read (*, '(a)', iostat=iostat) chr - write (*, '(a)') repeat('-', 60) - -end subroutine paws - -end program demo_run