I did find another way, which allows us to use %xdefine instead of %strcat everywhere. (The x is important, else it would lead to wrongly recursive macros.) This however requires a special "strlen"-like macro that counts string fragments as well as numbers, to figure out the length that the compound string-like list would take up when used with db
. Here's the full example, based on that part from my script already linked in the other answer.
%include "lmacros1.mac"
%macro checkchar 2-3.nolist 0
%if %2 <= ' ' || %2 >= 128 || \
%2 == '/' || %2 == '\' || \
%2 == '"' || %2 == "'" || \
%2 == %3
%error Invalid character (%2) in name (%1)
%endif
%endmacro
%macro strlen_ll 1-*.nolist
%assign ll 0
%rep %0
%ifstr %1
%strlen ll2 %1
%assign ll ll + ll2
%else
%assign ll ll + 1
%endif
%rotate 1
%endrep
%endmacro
%macro test 1
%define string %1
%strlen length string
%assign ii 1
%rep length
%substr cc string length - ii + 1
%ifidn cc,"/"
%substr string string length -ii + 2, -1
%exitrep
%endif
%ifidn cc,"\"
%substr string string length -ii + 2, -1
%exitrep
%endif
%assign ii ii + 1
%endrep
%strlen length string
%assign ii 1
%define name ""
%define ext ""
%assign dotyet 0
%rep length
%substr cc string ii
%assign ii ii + 1
%if cc >= 'a' && cc <= 'z'
%xdefine cc (cc - 'a' + 'A')
%endif
%ifn dotyet
%ifidn cc,"."
%assign dotyet 1
%else
strlen_ll name
%if ll >= 8
%error Too long name part in %1
%exitrep
%endif
checkchar %1,cc
%xdefine name name,cc
%endif
%else
strlen_ll ext
%if ll >= 3
%error Too long ext part in %1
%exitrep
%else
checkchar %1,cc,"."
%xdefine ext ext,cc
%endif
%endif
%endrep
%ifidn name,""
%error Invalid empty name part in %1
%endif
fill 8,32,db name
fill 3,32,db ext
%endmacro
test "../foo/bar/baz.bin"
test "quux"