#! /usr/bin/gawk -f # Last edited on 2021-03-03 16:48:22 by jstolfi /^[@][@]img/ { # Split the fields: lin = $0 gsub(/[}] *[{]/, "!!", lin) gsub(/^[@][@]img *[{]/, "!!", lin) gsub(/[}] *$/, "!!", lin) nf = split(lin,fld,"!!") if ((nf < 4) || (fld[1] != "") || (fld[nf] != "")) { data_error("bad @@img command") } # Create the image block: cap = fld[2] printf "
\n" printf "

" ni = nf-3 wd = 90/ni for (k = 0; k < ni; k++) { # Process one image: imgalt = fld[3+k] gsub(/^[ ]+/, "", imgalt) gsub(/[ ]+$/, "", imgalt) if (match(imgalt, /[ ]+/)) { img = substr(imgalt,1,RSTART-1) alt = substr(imgalt,RSTART+RLENGTH) } else { img = imgalt alt = "" } printf "\"%s\"", img, alt, img, wd } printf "
%s

\n", cap printf "
\n" # Preserve the original command as comment: printf "\n", $0 next } //{ print; next } function data_error(msg) { printf "%s:%d: ** %s", FILENAME, FNR, msg > "/dev/stderr" exit(1) }