From ad379018a4bce6c96dfa57747a241477a640e815 Mon Sep 17 00:00:00 2001 From: Philipp Date: Mon, 18 Nov 2024 22:12:27 +0100 Subject: [PATCH] Added version callback to arg parsing. --- app/dmbackup.f90 | 7 ++++++- app/dmbeat.f90 | 11 +++++++---- app/dmbot.f90 | 11 +++++++---- app/dmdb.f90 | 11 +++++++---- app/dmdbctl.f90 | 7 ++++++- app/dmexport.f90 | 7 ++++++- app/dmfeed.f90 | 11 +++++++---- app/dmfs.f90 | 7 ++++++- app/dmgrc.f90 | 7 ++++++- app/dmimport.f90 | 7 ++++++- app/dminfo.f90 | 7 ++++++- app/dminit.f90 | 7 ++++++- app/dmlog.f90 | 6 +++++- app/dmlogger.f90 | 11 +++++++---- app/dmlua.f90 | 7 ++++++- app/dmmbctl.f90 | 7 ++++++- app/dmpipe.f90 | 7 ++++++- app/dmplot.f90 | 23 +++++++++-------------- app/dmrecv.f90 | 7 ++++++- app/dmreport.f90 | 9 ++++++--- app/dmsend.f90 | 7 ++++++- app/dmserial.f90 | 7 ++++++- app/dmsync.f90 | 16 +++++++--------- app/dmuuid.f90 | 6 +++++- src/dm_arg.f90 | 43 ++++++++++++++++--------------------------- src/dm_plot.f90 | 2 +- 26 files changed, 168 insertions(+), 90 deletions(-) diff --git a/app/dmbackup.f90 b/app/dmbackup.f90 index 49d4bd6..dff5c75 100644 --- a/app/dmbackup.f90 +++ b/app/dmbackup.f90 @@ -91,7 +91,7 @@ integer function read_args(app) result(rc) ] ! Read all command-line arguments. - rc = dm_arg_read(args, APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH, dm_db_version(.true.)) + rc = dm_arg_read(args, version_callback) if (dm_is_error(rc)) return call dm_arg_get(args(1), app%database) @@ -125,4 +125,9 @@ subroutine backup_handler(remaining, page_count) write (*, '(a1, "[0GProgress: ", f5.1, " %")', advance='no') & ASCII_ESC, 100.0 * (page_count - remaining) / page_count end subroutine backup_handler + + subroutine version_callback() + call dm_version_out(APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH) + print '(a)', dm_db_version(.true.) + end subroutine version_callback end program dmbackup diff --git a/app/dmbeat.f90 b/app/dmbeat.f90 index 64693d6..7c35b00 100644 --- a/app/dmbeat.f90 +++ b/app/dmbeat.f90 @@ -79,8 +79,7 @@ integer function read_args(app) result(rc) !! Reads command-line arguments and settings from configuration file. type(app_type), intent(out) :: app !! App type. - character(len=:), allocatable :: version - type(arg_type) :: args(14) + type(arg_type) :: args(14) args = [ & arg_type('name', short='n', type=ARG_TYPE_ID), & ! -n, --name @@ -100,8 +99,7 @@ integer function read_args(app) result(rc) ] ! Read all command-line arguments. - version = dm_rpc_version() // ' ' // dm_lua_version(.true.) // ' ' // dm_zstd_version(.true.) - rc = dm_arg_read(args, APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH, version) + rc = dm_arg_read(args, version_callback) if (dm_is_error(rc)) return call dm_arg_get(args(1), app%name) @@ -344,4 +342,9 @@ subroutine signal_callback(signum) bind(c) call dm_stop(STOP_SUCCESS) end select end subroutine signal_callback + + subroutine version_callback() + call dm_version_out(APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH) + print '(a, 2(1x, a))', dm_rpc_version(), dm_lua_version(.true.), dm_zstd_version(.true.) + end subroutine version_callback end program dmbeat diff --git a/app/dmbot.f90 b/app/dmbot.f90 index 6b2c03e..7117e8c 100644 --- a/app/dmbot.f90 +++ b/app/dmbot.f90 @@ -171,8 +171,7 @@ integer function read_args(app, bot) result(rc) type(app_type), intent(out) :: app !! App type. type(bot_type), intent(out) :: bot !! Bot type. - character(len=:), allocatable :: version - type(arg_type) :: args(12) + type(arg_type) :: args(12) args = [ & arg_type('name', short='n', type=ARG_TYPE_ID), & ! -n, --name @@ -190,8 +189,7 @@ integer function read_args(app, bot) result(rc) ] ! Read all command-line arguments. - version = dm_lua_version(.true.) // ' ' // dm_db_version(.true.) - rc = dm_arg_read(args, APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH, version) + rc = dm_arg_read(args, version_callback) if (dm_is_error(rc)) return call dm_arg_get(args(1), app%name) @@ -909,4 +907,9 @@ subroutine signal_callback(signum) bind(c) call halt(E_NONE) end select end subroutine signal_callback + + subroutine version_callback() + call dm_version_out(APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH) + print '(a, 1x, a)', dm_lua_version(.true.), dm_db_version(.true.) + end subroutine version_callback end program dmbot diff --git a/app/dmdb.f90 b/app/dmdb.f90 index 4fad611..b1cf7b4 100644 --- a/app/dmdb.f90 +++ b/app/dmdb.f90 @@ -96,8 +96,7 @@ integer function read_args(app) result(rc) !! Reads command-line arguments and settings from configuration file. type(app_type), intent(out) :: app - character(len=:), allocatable :: version - type(arg_type) :: args(8) + type(arg_type) :: args(8) ! Required and optional command-line arguments. args = [ & @@ -112,8 +111,7 @@ integer function read_args(app) result(rc) ] ! Read all command-line arguments. - version = dm_lua_version(.true.) // ' ' // dm_db_version(.true.) - rc = dm_arg_read(args, APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH, version) + rc = dm_arg_read(args, version_callback) if (dm_is_error(rc)) return call dm_arg_get(args(1), app%name) @@ -295,4 +293,9 @@ subroutine signal_callback(signum) bind(c) call halt(E_NONE) end select end subroutine signal_callback + + subroutine version_callback() + call dm_version_out(APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH) + print '(a, 1x, a)', dm_lua_version(.true.), dm_db_version(.true.) + end subroutine version_callback end program dmdb diff --git a/app/dmdbctl.f90 b/app/dmdbctl.f90 index 231f449..36a8a7c 100644 --- a/app/dmdbctl.f90 +++ b/app/dmdbctl.f90 @@ -419,7 +419,7 @@ integer function read_args(app) result(rc) ] ! Read command-line arguments. - rc = dm_arg_read(args, APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH, dm_db_version(.true.)) + rc = dm_arg_read(args, version_callback) if (dm_is_error(rc)) return ! CRUD operation. @@ -553,4 +553,9 @@ integer function read_args(app) result(rc) ! Validation passed. rc = E_NONE end function read_args + + subroutine version_callback() + call dm_version_out(APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH) + print '(a)', dm_db_version(.true.) + end subroutine version_callback end program dmdbctl diff --git a/app/dmexport.f90 b/app/dmexport.f90 index 1df2e45..9ba38e9 100644 --- a/app/dmexport.f90 +++ b/app/dmexport.f90 @@ -182,7 +182,7 @@ integer function read_args(app) result(rc) ] ! Read all command-line arguments. - rc = dm_arg_read(args, APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH, dm_db_version(.true.)) + rc = dm_arg_read(args, version_callback) if (dm_is_error(rc)) return call dm_arg_get(args( 1), app%database) @@ -267,4 +267,9 @@ integer function read_args(app) result(rc) rc = E_NONE end function read_args + + subroutine version_callback() + call dm_version_out(APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH) + print '(a)', dm_db_version(.true.) + end subroutine version_callback end program dmexport diff --git a/app/dmfeed.f90 b/app/dmfeed.f90 index 2ec182e..a9d1772 100644 --- a/app/dmfeed.f90 +++ b/app/dmfeed.f90 @@ -77,8 +77,7 @@ integer function read_args(app) result(rc) !! `--config` is passed). type(app_type), intent(out) :: app !! App type. - character(len=:), allocatable :: version - type(arg_type) :: args(16) + type(arg_type) :: args(16) args = [ & arg_type('name', short='n', type=ARG_TYPE_ID), & ! -n, --name @@ -100,8 +99,7 @@ integer function read_args(app) result(rc) ] ! Read all command-line arguments. - version = dm_lua_version(.true.) // ' ' // dm_db_version(.true.) - rc = dm_arg_read(args, APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH, version) + rc = dm_arg_read(args, version_callback) if (dm_is_error(rc)) return call dm_arg_get(args(1), app%name) @@ -274,4 +272,9 @@ subroutine create_feed(app, error) if (present(error)) error = rc rc = dm_db_close(db) end subroutine create_feed + + subroutine version_callback() + call dm_version_out(APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH) + print '(a, 1x, a)', dm_lua_version(.true.), dm_db_version(.true.) + end subroutine version_callback end program dmfeed diff --git a/app/dmfs.f90 b/app/dmfs.f90 index d2cb80d..41a0ef1 100644 --- a/app/dmfs.f90 +++ b/app/dmfs.f90 @@ -124,7 +124,7 @@ integer function read_args(app) result(rc) ] ! Read all command-line arguments. - rc = dm_arg_read(args, APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH, dm_lua_version(.true.)) + rc = dm_arg_read(args, version_callback) if (dm_is_error(rc)) return call dm_arg_get(args(1), app%name) @@ -467,4 +467,9 @@ subroutine signal_callback(signum) bind(c) call dm_stop(STOP_SUCCESS) end select end subroutine signal_callback + + subroutine version_callback() + call dm_version_out(APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH) + print '(a)', dm_lua_version(.true.) + end subroutine version_callback end program dmfs diff --git a/app/dmgrc.f90 b/app/dmgrc.f90 index 4e82400..e0e8581 100644 --- a/app/dmgrc.f90 +++ b/app/dmgrc.f90 @@ -94,7 +94,7 @@ integer function read_args(app) result(rc) ] ! Read all command-line arguments. - rc = dm_arg_read(args, APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH, dm_lua_version(.true.)) + rc = dm_arg_read(args, version_callback) if (dm_is_error(rc)) return call dm_arg_get(args(1), app%name) @@ -306,4 +306,9 @@ subroutine signal_callback(signum) bind(c) call halt(E_NONE) end select end subroutine signal_callback + + subroutine version_callback() + call dm_version_out(APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH) + print '(a)', dm_lua_version(.true.) + end subroutine version_callback end program dmgrc diff --git a/app/dmimport.f90 b/app/dmimport.f90 index f528528..17919eb 100644 --- a/app/dmimport.f90 +++ b/app/dmimport.f90 @@ -270,7 +270,7 @@ integer function read_args(app) result(rc) ] ! Read all command-line arguments. - rc = dm_arg_read(args, APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH, dm_db_version(.true.)) + rc = dm_arg_read(args, version_callback) if (dm_is_error(rc)) return call dm_arg_get(args(1), type_name) @@ -308,4 +308,9 @@ integer function read_args(app) result(rc) rc = E_NONE end function read_args + + subroutine version_callback() + call dm_version_out(APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH) + print '(a)', dm_db_version(.true.) + end subroutine version_callback end program dmimport diff --git a/app/dminfo.f90 b/app/dminfo.f90 index 09ff929..d176dda 100644 --- a/app/dminfo.f90 +++ b/app/dminfo.f90 @@ -40,7 +40,7 @@ integer function read_args(app) result(rc) arg_type(name='database', short='d', type=ARG_TYPE_DATABASE) & ! -d, --database ] - rc = dm_arg_read(args, APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH, dm_db_version(.true.)) + rc = dm_arg_read(args, version_callback) call dm_arg_get(args(1), app%database) rc = E_NONE end function read_args @@ -145,4 +145,9 @@ integer function output_info(app) result(rc) print '("system.time.zone: ", a)', dm_time_zone() print '("system.version: ", a)', trim(uname%version) end function output_info + + subroutine version_callback() + call dm_version_out(APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH) + print '(a)', dm_db_version(.true.) + end subroutine version_callback end program dminfo diff --git a/app/dminit.f90 b/app/dminit.f90 index 768b338..6d03212 100644 --- a/app/dminit.f90 +++ b/app/dminit.f90 @@ -100,7 +100,7 @@ integer function read_args(app) result(rc) ] ! Read all command-line arguments. - rc = dm_arg_read(args, APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH, dm_db_version(.true.)) + rc = dm_arg_read(args, version_callback) if (dm_is_error(rc)) return ! Database type (observ, log, beat). @@ -130,4 +130,9 @@ integer function read_args(app) result(rc) rc = E_NONE end function read_args + + subroutine version_callback() + call dm_version_out(APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH) + print '(a)', dm_db_version(.true.) + end subroutine version_callback end program dminit diff --git a/app/dmlog.f90 b/app/dmlog.f90 index d2678e7..5c800b2 100644 --- a/app/dmlog.f90 +++ b/app/dmlog.f90 @@ -62,7 +62,7 @@ integer function read_args(app, log) result(rc) ] ! Read all command-line arguments. - rc = dm_arg_read(args, APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH) + rc = dm_arg_read(args, version_callback) if (dm_is_error(rc)) return call dm_arg_get(args( 1), app%logger) @@ -85,4 +85,8 @@ integer function read_args(app, log) result(rc) rc = E_NONE end function read_args + + subroutine version_callback() + call dm_version_out(APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH) + end subroutine version_callback end program dmlog diff --git a/app/dmlogger.f90 b/app/dmlogger.f90 index b2c7788..207d2d9 100644 --- a/app/dmlogger.f90 +++ b/app/dmlogger.f90 @@ -92,8 +92,7 @@ integer function read_args(app) result(rc) !! Reads command-line arguments and settings from configuration file. type(app_type), intent(out) :: app - character(len=:), allocatable :: version - type(arg_type) :: args(7) + type(arg_type) :: args(7) ! Required and optional command-line arguments. args = [ & @@ -107,8 +106,7 @@ integer function read_args(app) result(rc) ] ! Read all command-line arguments. - version = dm_lua_version(.true.) // ' ' // dm_db_version(.true.) - rc = dm_arg_read(args, APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH, version) + rc = dm_arg_read(args, version_callback) if (dm_is_error(rc)) return call dm_arg_get(args(1), app%name) @@ -289,4 +287,9 @@ subroutine signal_callback(signum) bind(c) call halt(0) end select end subroutine signal_callback + + subroutine version_callback() + call dm_version_out(APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH) + print '(a, 1x, a)', dm_lua_version(.true.), dm_db_version(.true.) + end subroutine version_callback end program dmlogger diff --git a/app/dmlua.f90 b/app/dmlua.f90 index 8a49ac1..4953c21 100644 --- a/app/dmlua.f90 +++ b/app/dmlua.f90 @@ -125,7 +125,7 @@ integer function read_args(app) result(rc) ] ! Read all command-line arguments. - rc = dm_arg_read(args, APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH, dm_lua_version(.true.)) + rc = dm_arg_read(args, version_callback) if (dm_is_error(rc)) return call dm_arg_get(args(1), app%name) @@ -319,4 +319,9 @@ subroutine signal_callback(signum) bind(c) call halt(E_NONE) end select end subroutine signal_callback + + subroutine version_callback() + call dm_version_out(APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH) + print '(a)', dm_lua_version(.true.) + end subroutine version_callback end program dmlua diff --git a/app/dmmbctl.f90 b/app/dmmbctl.f90 index 176ab0d..3aa2e9c 100644 --- a/app/dmmbctl.f90 +++ b/app/dmmbctl.f90 @@ -89,7 +89,7 @@ integer function read_args(app) result(rc) ] ! Read all command-line arguments. - rc = dm_arg_read(args, APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH, dm_modbus_version(.true.)) + rc = dm_arg_read(args, version_callback) if (dm_is_error(rc)) return call dm_arg_get(args( 1), app%rtu%path, passed=has_path) @@ -286,4 +286,9 @@ integer function read_args(app) result(rc) rc = E_NONE end function read_args + + subroutine version_callback() + call dm_version_out(APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH) + print '(a)', dm_modbus_version(.true.) + end subroutine version_callback end program dmmbctl diff --git a/app/dmpipe.f90 b/app/dmpipe.f90 index b549c90..ce4f27d 100644 --- a/app/dmpipe.f90 +++ b/app/dmpipe.f90 @@ -124,7 +124,7 @@ integer function read_args(app) result(rc) ] ! Read all command-line arguments. - rc = dm_arg_read(args, APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH, dm_lua_version(.true.)) + rc = dm_arg_read(args, version_callback) if (dm_is_error(rc)) return call dm_arg_get(args(1), app%name) @@ -452,4 +452,9 @@ subroutine signal_callback(signum) bind(c) call dm_stop(STOP_SUCCESS) end select end subroutine signal_callback + + subroutine version_callback() + call dm_version_out(APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH) + print '(a)', dm_lua_version(.true.) + end subroutine version_callback end program dmpipe diff --git a/app/dmplot.f90 b/app/dmplot.f90 index f23a62f..5a7a6d3 100644 --- a/app/dmplot.f90 +++ b/app/dmplot.f90 @@ -120,8 +120,6 @@ integer function read_args(app) result(rc) type(app_type), intent(out) :: app !! App type. character(len=PLOT_TERMINAL_NAME_LEN) :: terminal - character(len=:), allocatable :: version - logical :: found type(arg_type) :: args(17) args = [ & @@ -144,19 +142,8 @@ integer function read_args(app) result(rc) arg_type('height', short='H', type=ARG_TYPE_INTEGER) & ! -H, --height ] - ! Create version string and search for Gnuplot. - version = dm_plot_version(.true., found) // ' ' // & - dm_lua_version(.true.) // ' ' // & - dm_db_version(.true.) - - if (.not. found) then - rc = E_NOT_FOUND - call dm_error_out(rc, 'Gnuplot not found') - return - end if - ! Read all command-line arguments. - rc = dm_arg_read(args, APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH, version) + rc = dm_arg_read(args, version_callback) if (dm_is_error(rc)) return call dm_arg_get(args(1), app%name) @@ -310,4 +297,12 @@ integer function read_data_points(dps, database, node, sensor, target, response, rc = max(dm_db_close(db), rc) end function read_data_points + + subroutine version_callback() + logical :: found + + call dm_version_out(APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH) + print '(a, 2(1x, a))', dm_plot_version(.true., found), dm_lua_version(.true.), dm_db_version(.true.) + if (.not. found) call dm_error_out(E_NOT_FOUND, 'Gnuplot binary not found') + end subroutine version_callback end program dmplot diff --git a/app/dmrecv.f90 b/app/dmrecv.f90 index ac9308c..4e27380 100644 --- a/app/dmrecv.f90 +++ b/app/dmrecv.f90 @@ -111,7 +111,7 @@ integer function read_args(app) result(rc) ] ! Read all command-line arguments. - rc = dm_arg_read(args, APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH, dm_lua_version(.true.)) + rc = dm_arg_read(args, version_callback) if (dm_is_error(rc)) return call dm_arg_get(args(1), app%name) @@ -399,4 +399,9 @@ subroutine signal_callback(signum) bind(c) call halt(E_NONE) end select end subroutine signal_callback + + subroutine version_callback() + call dm_version_out(APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH) + print '(a)', dm_lua_version(.true.) + end subroutine version_callback end program dmrecv diff --git a/app/dmreport.f90 b/app/dmreport.f90 index 379a2b0..73cc835 100644 --- a/app/dmreport.f90 +++ b/app/dmreport.f90 @@ -155,7 +155,6 @@ integer function read_args(app) result(rc) !! Reads command-line arguments and settings from file. type(app_type), target, intent(out) :: app !! App type. - character(len=:), allocatable :: version integer :: format, i, n type(arg_type) :: args(7) type(report_log_type), pointer :: log @@ -172,8 +171,7 @@ integer function read_args(app) result(rc) ] ! Read all command-line arguments. - version = dm_plot_version(.true.) // ' ' // dm_lua_version(.true.) // ' ' // dm_db_version(.true.) - rc = dm_arg_read(args, APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH, version) + rc = dm_arg_read(args, version_callback) if (dm_is_error(rc)) return call dm_arg_get(args(1), app%name) @@ -528,4 +526,9 @@ subroutine create_report(report, error) if (is_file) close (unit) if (present(error)) error = rc end subroutine create_report + + subroutine version_callback() + call dm_version_out(APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH) + print '(a, 2(1x, a))', dm_plot_version(.true.), dm_lua_version(.true.), dm_db_version(.true.) + end subroutine version_callback end program dmreport diff --git a/app/dmsend.f90 b/app/dmsend.f90 index c82aa04..84d2f91 100644 --- a/app/dmsend.f90 +++ b/app/dmsend.f90 @@ -78,7 +78,7 @@ integer function read_args(app) result(rc) ] ! Read all command-line arguments. - rc = dm_arg_read(args, APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH, dm_lua_version(.true.)) + rc = dm_arg_read(args, version_callback) if (dm_is_error(rc)) return call dm_arg_get(args(1), app%name) @@ -323,4 +323,9 @@ integer function run(app) result(rc) call logger%debug('finished transmission of ' // dm_itoa(nrecords) // ' records') end function run + + subroutine version_callback() + call dm_version_out(APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH) + print '(a)', dm_lua_version(.true.) + end subroutine version_callback end program dmsend diff --git a/app/dmserial.f90 b/app/dmserial.f90 index 4dbe40c..71a5ab9 100644 --- a/app/dmserial.f90 +++ b/app/dmserial.f90 @@ -189,7 +189,7 @@ integer function read_args(app) result(rc) ] ! Read all command-line arguments. - rc = dm_arg_read(args, APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH, dm_lua_version(.true.)) + rc = dm_arg_read(args, version_callback) if (dm_is_error(rc)) return call dm_arg_get(args(1), app%name) @@ -612,4 +612,9 @@ subroutine signal_callback(signum) bind(c) call dm_stop(STOP_SUCCESS) end select end subroutine signal_callback + + subroutine version_callback() + call dm_version_out(APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH) + print '(a)', dm_lua_version(.true.) + end subroutine version_callback end program dmserial diff --git a/app/dmsync.f90 b/app/dmsync.f90 index 0784a29..ccfedcf 100644 --- a/app/dmsync.f90 +++ b/app/dmsync.f90 @@ -118,8 +118,7 @@ integer function read_args(app) result(rc) !! Reads command-line arguments and settings from configuration file. type(app_type), intent(out) :: app - character(len=:), allocatable :: version - type(arg_type) :: args(17) + type(arg_type) :: args(17) args = [ & arg_type('name', short='n', type=ARG_TYPE_ID), & ! -n, --name @@ -141,14 +140,8 @@ integer function read_args(app) result(rc) arg_type('verbose', short='V', type=ARG_TYPE_LOGICAL) & ! -V, --verbose ] - ! Generate version string. - version = dm_rpc_version() // ' ' // & - dm_lua_version(.true.) // ' ' // & - dm_db_version(.true.) // ' ' // & - dm_zstd_version(.true.) - ! Read all command-line arguments. - rc = dm_arg_read(args, APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH, version) + rc = dm_arg_read(args, version_callback) if (dm_is_error(rc)) return call dm_arg_get(args(1), app%name) @@ -615,4 +608,9 @@ subroutine signal_callback(signum) bind(c) call halt(E_NONE) end select end subroutine signal_callback + + subroutine version_callback() + call dm_version_out(APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH) + print '(a, 3(1x, a))', dm_rpc_version(), dm_lua_version(.true.), dm_db_version(.true.), dm_zstd_version(.true.) + end subroutine version_callback end program dmsync diff --git a/app/dmuuid.f90 b/app/dmuuid.f90 index 1cb8b7b..e811195 100644 --- a/app/dmuuid.f90 +++ b/app/dmuuid.f90 @@ -61,7 +61,7 @@ integer function read_args(app) result(rc) ] ! Read all command-line arguments. - rc = dm_arg_read(args, APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH) + rc = dm_arg_read(args, version_callback) if (dm_is_error(rc)) return call dm_arg_get(args(1), app%convert) @@ -101,4 +101,8 @@ subroutine convert() print '(a)', dm_uuid4_hyphenize(uuid) end do end subroutine convert + + subroutine version_callback() + call dm_version_out(APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH) + end subroutine version_callback end program dmuuid diff --git a/src/dm_arg.f90 b/src/dm_arg.f90 index cc8f54b..42caa28 100644 --- a/src/dm_arg.f90 +++ b/src/dm_arg.f90 @@ -54,6 +54,11 @@ module dm_arg integer, parameter, public :: ARG_NAME_LEN = 32 !! Maximum length of argument name. integer, parameter, public :: ARG_VALUE_LEN = FILE_PATH_LEN !! Maximum length of argument value. + abstract interface + subroutine dm_arg_version_callback() + end subroutine dm_arg_version_callback + end interface + type, public :: arg_type !! Argument description type. character(len=ARG_NAME_LEN) :: name = ' ' !! Identifier of the argument (without leading --). @@ -83,6 +88,7 @@ module dm_arg public :: dm_arg_read public :: dm_arg_type_is_valid public :: dm_arg_validate + public :: dm_arg_version_callback private :: arg_get_int32 private :: arg_get_logical @@ -220,7 +226,7 @@ integer function dm_arg_parse(args, ignore_unknown, verbose) result(rc) rc = E_NONE end function dm_arg_parse - integer function dm_arg_read(args, app, major, minor, patch, version) result(rc) + integer function dm_arg_read(args, callback) result(rc) !! Reads all arguments from command-line and prints error message if one !! is missing. Returns the error code of the first invalid argument. !! @@ -230,8 +236,8 @@ integer function dm_arg_read(args, app, major, minor, patch, version) result(rc) !! arguments. If one of these arguments is passed, `dm_stop(0)` is !! called afterwards. !! - !! Optional argument `version` may be a string of third-party library - !! names and version numbers. + !! Optional argument `callback` is a routine that outputs the + !! version information. !! !! The function returns the following error codes: !! @@ -244,39 +250,21 @@ integer function dm_arg_read(args, app, major, minor, patch, version) result(rc) !! use :: dm_version - type(arg_type), intent(inout) :: args(:) !! Arguments to match. - character(len=*), intent(in), optional :: app !! App name (for `-v`). - integer, intent(in), optional :: major !! Major version number (for `-v`). - integer, intent(in), optional :: minor !! Minor version number (for `-v`). - integer, intent(in), optional :: patch !! Patch level (for `-v`). - character(len=*), intent(in), optional :: version !! Additional version string. + type(arg_type), intent(inout) :: args(:) !! Arguments to match. + procedure(dm_arg_version_callback), optional :: callback !! Version callback. integer :: i, n - integer :: major_, minor_, patch_ integer :: max_len, min_len rc = E_NONE - major_ = 0 - minor_ = 0 - patch_ = 0 - - if (present(major)) major_ = major - if (present(minor)) minor_ = minor - if (present(patch)) patch_ = patch - - ! Print program and library version, then stop. + ! Call version callback, then stop. if (dm_arg_has('version', 'v')) then - if (present(app)) then - call dm_version_out(app, major_, minor_, patch_) + if (present(callback)) then + call callback() else write (stdout, '("DMPACK ", a)') DM_VERSION_STRING end if - - if (present(version)) then - write (stdout, '(a)') trim(version) - end if - call dm_stop(STOP_SUCCESS) end if @@ -298,7 +286,8 @@ integer function dm_arg_read(args, app, major, minor, patch, version) result(rc) ! Validate passed arguments. rc = E_EMPTY - validate_loop: do i = 1, size(args) + validate_loop: & + do i = 1, size(args) if (.not. dm_arg_type_is_valid(args(i)%type)) then call dm_error_out(E_TYPE, 'argument --' // trim(args(i)%name) // ' has no valid type') cycle diff --git a/src/dm_plot.f90 b/src/dm_plot.f90 index fe46742..9d6e3a7 100644 --- a/src/dm_plot.f90 +++ b/src/dm_plot.f90 @@ -212,7 +212,7 @@ function dm_plot_version(name, found) result(version) logical, intent(in), optional :: name !! Add prefix `gnuplot/`. logical, intent(out), optional :: found !! Returns `.true.` if Gnuplot has been found. - character(len=:), allocatable :: version + character(len=:), allocatable :: version character(len=3) :: v character(len=32) :: buffer