]> git.draconx.ca Git - dxcommon.git/blob - m4/basename.m4
Avoid nonportable ${x##y} substitutions in program tests.
[dxcommon.git] / m4 / basename.m4
1 dnl Copyright © 2021 Nick Bowler
2 dnl
3 dnl License WTFPL2: Do What The Fuck You Want To Public License, version 2.
4 dnl This is free software: you are free to do what the fuck you want to.
5 dnl There is NO WARRANTY, to the extent permitted by law.
6
7 dnl DX_BASENAME(variable, string)
8 dnl
9 dnl If string, which must be a single shell word, contains a / character,
10 dnl variable is assigned to the portion of string that follows the last
11 dnl such character.  Otherwise, variable is set to string.
12 AC_DEFUN([DX_BASENAME],
13 [AC_REQUIRE([_DX_BASENAME_SETUP])dnl
14 dx_fn_basename $1 $2])
15
16 AC_DEFUN_ONCE([_DX_BASENAME_SETUP], [m4_divert_push([INIT_PREPARE])dnl
17 dx_fn_basename () {
18   _dx_tmp=; { _dx_tmp=${2##*/}; } 2>/dev/null
19   AS_CASE([$_dx_tmp], [""], [_dx_save_IFS=$IFS; IFS=/
20     for _dx_tmp in $][2; do :; done
21     IFS=$_dx_save_IFS])
22   AS_VAR_SET([$][1], [$_dx_tmp])
23 }
24 m4_divert_pop()])