Skip to content

Commit

Permalink
Minor updates and additions.
Browse files Browse the repository at this point in the history
  • Loading branch information
interkosmos committed Oct 19, 2024
1 parent 5130086 commit 88232ad
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
8 changes: 4 additions & 4 deletions app/dmbot.f90
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ program dmbot
integer, parameter :: BOT_NCOMMANDS = 11 !! Number of commands.

integer, parameter :: BOT_COMMAND_NAME_LEN = 9 !! Max. command name length.
integer, parameter :: BOT_COMMAND_LEN = 1 + BOT_COMMAND_NAME_LEN !! Max. command length with prefix `!`.
integer, parameter :: BOT_COMMAND_LEN = 1 + BOT_COMMAND_NAME_LEN !! Max. command length with prefix.

character, parameter :: BOT_COMMAND_PREFIX = '!' !! Command prefix.
character(len=BOT_COMMAND_NAME_LEN), parameter :: BOT_COMMAND_NAMES(BOT_NCOMMANDS) = [ &
Expand Down Expand Up @@ -98,6 +98,9 @@ program dmbot
call logger%info('started ' // APP_NAME)

do
! Register signal handler.
call dm_signal_register(signal_callback)

! Create libstrophe context.
rc = dm_im_create(bot%im)

Expand Down Expand Up @@ -125,9 +128,6 @@ program dmbot
exit init_block
end if

! Register signal handler.
call dm_signal_register(signal_callback)

! Check if authorisation is enabled.
if (size(bot%group) == 0) then
call logger%info('bot accepts requests from all clients (authorization is disabled)')
Expand Down
28 changes: 26 additions & 2 deletions src/dm_gm.f90
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ module dm_gm
public :: dm_gm_get_directory
public :: dm_gm_get_file_extension
public :: dm_gm_get_file_format
public :: dm_gm_get_file_name
public :: dm_gm_get_mime

private :: gm_identify
Expand Down Expand Up @@ -469,12 +470,31 @@ integer function dm_gm_get_file_format(path, file_format) result(rc)
character(len=*), intent(in) :: path !! Image file path.
character(len=:), allocatable, intent(out) :: file_format !! Image file format.

character(len=32) :: buffer
character(len=16) :: buffer

rc = gm_identify(path, '%m', buffer)
file_format = trim(buffer)
end function dm_gm_get_file_format

integer function dm_gm_get_file_name(path, file_name) result(rc)
!! Uses GraphicsMagick to return the file name part of the image path.
!! On error, the string `file_name` is allocated but empty.
!!
!! The function returns the followin error codes:
!!
!! * `E_NOT_FOUND` if image does not exist.
!! * `E_READ` if reading dimensions failed.
!! * `E_SYSTEM` if execution of GraphicsMagick failed.
!!
character(len=*), intent(in) :: path !! Image file path.
character(len=:), allocatable, intent(out) :: file_name !! Image file name.

character(len=512) :: buffer

rc = gm_identify(path, '%f', buffer)
file_name = trim(buffer)
end function dm_gm_get_file_name

integer function dm_gm_get_mime(path, mime) result(rc)
!! Determines the MIME type of the image through file format. The
!! following file formats are recognised: GIF, JPEG, PNG, SVG. On
Expand Down Expand Up @@ -507,11 +527,13 @@ end function dm_gm_get_mime
! **************************************************************************
integer function gm_identify(path, format, output) result(rc)
!! Identifies image with GraphicsMagick and returns result in `output`.
!!
!! * [GraphicMagick format characters](http://www.graphicsmagick.org/GraphicsMagick.html#details-format)
use :: dm_kind
use :: dm_pipe

character(len=*), intent(in) :: path !! Image file path.
character(len=*), intent(in) :: format !! GraphicsMagick identify format attributes.
character(len=*), intent(in) :: format !! GraphicsMagick format attributes.
character(len=*), intent(inout) :: output !! Output string.

integer(kind=i8) :: n
Expand Down Expand Up @@ -545,6 +567,8 @@ end function gm_identify
subroutine gm_prepare_add_text_box(command, path, text, text_box)
!! Prepares GraphicsMagick command to add text to image. The string
!! `text` must not contain the quote characters `'` and `"`.
!!
!! * [GraphicsMagick draw command](http://www.graphicsmagick.org/GraphicsMagick.html#details-draw)
character(len=GM_COMMAND_LEN), intent(out) :: command !! Prepared command string.
character(len=*), intent(in) :: path !! Image file path.
character(len=*), intent(in) :: text !! Text to add.
Expand Down

0 comments on commit 88232ad

Please sign in to comment.