Which is preferable, more elegant generated C++ code or simpler code used to generate it? The attached fdfix.diff is used to create the diff below.
Should I commit fdfix.diff or leave things as they are? Angus ========================================================= forms/form_document.C: // This file is part of LyX, the document processor. // Licence details can be found in the file COPYING. -namespace { -char const * c_str; -} // namespace anon - #include <config.h> ... FD_document * build_document(void * parent) { + char const * c_str; FL_OBJECT * obj; ... FD_document_paper * build_document_paper(void * parent) { + char const * c_str; FL_OBJECT * obj; ... FD_document_class * build_document_class(void * parent) { + char const * c_str; FL_OBJECT * obj; ... FD_document_language * build_document_language(void * parent) { + char const * c_str; FL_OBJECT * obj; ... FD_document_options * build_document_options(void * parent) { + char const * c_str; FL_OBJECT * obj; ... FD_document_bullet * build_document_bullet(void * parent) { + char const * c_str; FL_OBJECT * obj;
? fdfix.diff Index: fdfix.sh =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/xforms/forms/fdfix.sh,v retrieving revision 1.22 diff -u -p -r1.22 fdfix.sh --- fdfix.sh 26 Nov 2002 19:29:39 -0000 1.22 +++ fdfix.sh 27 Nov 2002 15:15:22 -0000 @@ -121,17 +121,6 @@ FDFIXC=${DIRNAME}/fdfixc.sed OUTPUT_FILE=${COUT}; INTRO_MESSAGE -# This "c_str" is potentially used many times in many functions -# so add it to the top of the generated file. -grep -E 'fl_add.*".*[|].*"' ${CIN} > /dev/null && - cat - >> ${COUT} <<EOF -namespace { -char const * c_str; -} // namespace anon - - -EOF - echo "#include <config.h>" >> ${COUT} echo "#include \"forms_gettext.h\"" >> ${COUT} echo "#include \"gettext.h\"" >> ${COUT} Index: fdfixc.sed =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/xforms/forms/fdfixc.sed,v retrieving revision 1.11 diff -u -p -r1.11 fdfixc.sed --- fdfixc.sed 26 Nov 2002 19:29:39 -0000 1.11 +++ fdfixc.sed 27 Nov 2002 15:15:22 -0000 @@ -35,24 +35,42 @@ s/FD_form_\(.*\)/FD_\1/ # Rename the function create_form_form_xxx(void) as build_xxx() +# Use it to initialise the hold space, deleting it from the pattern space. +/create_form_form/ { s/\(.*\) \*create_form_form_\(.*\)\([(]void[)]\)/\ \ \1 * build_\2(void * parent)/ +h; d +} + + +# Append to the hold space +/^{$/ { +H; d +} + +# All indented lines are inside the function body. +# Append to the hold space. +/^ / { # Pretty formatting s/FL_OBJECT \*obj;/FL_OBJECT * obj;\ / # Insert a line before each new FL_OBJECT -/obj = /i\ +# We murder s/// in this way rather than use i\ because insert does not modify +# the pattern space (which we subsequently store in the hold space). +s/\(.*obj =\)/\ +\1/ # Ditto for fl_bgn -/fl_bgn/i\ +s/\(.*fl_bgn\)/\ +\1/ # Ditto for fl_end -/fl_end/i\ - +s/\(.*fl_end\)/\ +\1/ # Rewrite "fdui->form_xxx" as "fdui->form" # xxx is followed by ' ', '->' or ')', so use these to flag when xxx ends. @@ -99,8 +117,10 @@ s/\( fdui->form\)\(.*bgn_form.*\)/\1\2\ # gettext will get confused if the string contains a "%" unless the line is # preceeded immediately by "// xgettext:no-c-format" -/_(".*[%].*")/i\ - // xgettext:no-c-format +# We murder s/// in this way rather than use i\ because insert does not modify +# the pattern space. +s/\(.*_(".*[%].*")\)/\ + \/\/ xgettext:no-c-format\1/ # Someone got busy and put spaces in after commas but didn't allow for the @@ -112,3 +132,20 @@ s/,\([^ ]\)/, \1/g # while ensuring "...", "..." isn't affected. # s/\("[^"]+,\) \("\)/\1\2/g + +# Don't forget to append this stuff to the hold space +H; d +} + +# The end of the function. +/^}$/ { + +# Paste the contents of the hold space back into the pattern space above it. +x; G + +# If the pattern space contains "c_str", then declare it at the top of the +# function. +/c_str/s/\( FL_OBJECT \*\)/ char const * c_str;\ +\1/ + +}