Michael Phipps wrote:
Niels Reedijk wrote:The second tool is probably going to be a custom made tool. I thought of a linking system to link between classes. In order to do this in a less errorprone way I need to autogenerate a set of entities to link between classes. Entities are aliases for longer pieces of docbook. For example, I need to create an entity &BString_Length; that expands to <link linkend="bstring_length"><function>Length()</function></link>. Creating this manually is quite tedious (check midi2api.xml) so this needs to be automated. I'm not very good at perl or python or any other quick tool that can be used to write such a script, but I would be able to explain very briefly to someone who can, what it should do exactly.Maybe it is just me, but I don't understand what you are getting at, here. If what you wrote is, literally, what you want, then: sed 's: &\([^_]*\)_\([^;]*\): <link linkend="\1"><function>\2()</function></link>' foo > foo.fixed will do the trick (without the linewraps, of course)...
Ahem. OK, let me try that again: sed 's: &\([^_]*\)_\([^;]*\): <link linkend="\1_\2"><function>\2()</function></link>' foo > foo.fixed If the caps changes are needed, I would use awk: awk ' $0 ~ /.*&[A-z]*_[A-z]*;.*/ { while (match($0,/&[A-z]*_[A-z]*;/) { wholeName=substr($0,RSTART,RLENGTH) under=index(wholeName,'_') class=substr(wholeName,2,under) method=substr(wholeName,1+under,length(wholeName)-under)replace="<link linkend=\"" + tolower(class) + "_" + tolower(method) + "\"><function>" + method + "()</function></link>"
$0=sub($0,1,RSTART) + replace + sub($0,RSTART+RLENGTH) } } print ' foo > foo.fixedAll of this is untested code, of course, so there will be some debugging, I am sure. Still, I think that sed and/or awk is better than introducing the requirement for a new language in our build system. KISS :)
Michael