#!/bin/sed -nsf # begin of file, declare file 1{ /@file/!{ # no file definition yet, add it x s,^, @file\n, x } } # line with doxygen comment (defined as ## at begin of line) /^##\( \|$\)/{ s/##\( \|$\)/ / # replace ## comments by 4 spaces indent H; d # hold, evaluate later } # variable definition /^set/{ s,^set \+\([^ =]\+\)\( *= *\(.*\)\)\?,/** @var \1, # prepend variable decl G # append hold buffer s,$, */\n, # append end of comment p; z; x; d # clear buffer, next line } # function definition /^function/{ s,^function \+\([^ ]\+\) *\(.*\)\?,/** @fn \1(\2), # prepend function decl G # append hold buffer s,$, */\n, # append end of comment p; z; x; d # clear buffer, next line } # default for non matching lines - print buffer { z; x; # get and clear buffer /^$/!{ # only if buffer is not empty s,^\n,, # remove first newline s,^\( \)\?,/** , # prepend doxygen comment start s,$, */\n, # append end of comment p; d } }