52 lines
1.7 KiB
Plaintext
52 lines
1.7 KiB
Plaintext
divert(`-1')dnl
|
|
changequote(`«', `»')
|
|
changecom(«\»)
|
|
\ note: use https://github.com/vim-scripts/syntaxm4.vim.git
|
|
vim-m4-syntax: quote=«,» comment=\\
|
|
|
|
\ forloop(var, from, to, stmt) - improved version:
|
|
\ works even if VAR is not a strict macro name
|
|
\ performs sanity check that FROM is larger than TO
|
|
\ allows complex numerical expressions in TO and FROM
|
|
define(«forloop», «ifelse(eval(«($2) <= ($3)»), «1»,
|
|
«pushdef(«$1»)_$0(«$1», eval(«$2»),
|
|
eval(«$3»), «$4»)popdef(«$1»)»)»)
|
|
define(«_forloop»,
|
|
«define(«$1», «$2»)$4«»ifelse(«$2», «$3», «»,
|
|
«$0(«$1», incr(«$2»), «$3», «$4»)»)»)
|
|
|
|
\ foreachq(x, «item_1, item_2, ..., item_n», stmt)
|
|
\ quoted list, version based on forloop
|
|
define(«foreachq»,
|
|
«ifelse(«$2», «», «», «_$0(«$1», «$3», $2)»)»)
|
|
define(«_foreachq»,
|
|
«pushdef(«$1», forloop(«$1», «3», «$#»,
|
|
«$0_(«1», «2», indir(«$1»))»)«popdef(
|
|
«$1»)»)indir(«$1», $@)»)
|
|
define(«_foreachq_»,
|
|
««define(«$$1», «$$3»)$$2«»»»)
|
|
|
|
\ foreach(x, (item_1, item_2, ..., item_n), stmt)
|
|
\ parenthesized list, improved version
|
|
define(«foreach», «pushdef(«$1»)_$0(«$1»,
|
|
(dquote(dquote_elt$2)), «$3»)popdef(«$1»)»)
|
|
define(«_arg1», «$1»)
|
|
define(«_foreach», «ifelse(«$2», «(«»)», «»,
|
|
«define(«$1», _arg1$2)$3«»$0(«$1», (dquote(shift$2)), «$3»)»)»)
|
|
|
|
\ hextox(x)
|
|
\ hexadecimal number to series of X(0xZZ)X(0xZZ)...
|
|
define(«hextox», «patsubst(«$1», «..», «X(0x\&)»)»)
|
|
|
|
\ hashtag(x)
|
|
\ expands to #x
|
|
define(«hashtag», «changecom()dnl
|
|
#$1«»dnl
|
|
changecom(«#»)»)
|
|
|
|
\ rtrimn(x, n)
|
|
\ expands to all but the last n characters of x
|
|
define(«rtrimn», «substr($1, 0, eval(len($1)-$2))»)
|
|
|
|
divert(«0»)dnl
|