From 8903a92aeab4f118527420b7ac92481c6a834c8a Mon Sep 17 00:00:00 2001 From: Angus Leeming Date: Thu, 21 Nov 2002 10:58:28 +0000 Subject: [PATCH] I reckon that the generated .h files and the scripts that modify them aren't do bad now. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@5689 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/xforms/ChangeLog | 6 ++ src/frontends/xforms/forms/fdfix.sh | 36 +++++++---- src/frontends/xforms/forms/fdfixh.sed | 89 ++++++++++++++------------- 3 files changed, 77 insertions(+), 54 deletions(-) diff --git a/src/frontends/xforms/ChangeLog b/src/frontends/xforms/ChangeLog index 54df903bb2..2654b740cb 100644 --- a/src/frontends/xforms/ChangeLog +++ b/src/frontends/xforms/ChangeLog @@ -1,3 +1,9 @@ +2002-11-20 Angus Leeming + + * forms/fdfix.sh: + * forms/fdfixh.sed: strengthen the sed in the sed script and further + beautify the contents of the resultant .h file. + 2002-11-20 Angus Leeming * MathsCallbacks.h: removed. diff --git a/src/frontends/xforms/forms/fdfix.sh b/src/frontends/xforms/forms/fdfix.sh index 4e6f8c4984..4ed635f5c4 100644 --- a/src/frontends/xforms/forms/fdfix.sh +++ b/src/frontends/xforms/forms/fdfix.sh @@ -29,6 +29,7 @@ cat - > ${OUTPUT_FILE} < ${EXTERN_FUNCS} + +if [ -s ${EXTERN_FUNCS} ]; then + sort -u ${EXTERN_FUNCS} > tmp + echo "extern \"C\" {" > ${EXTERN_FUNCS} + cat tmp >> ${EXTERN_FUNCS} + echo "}" >> ${EXTERN_FUNCS} + rm -f tmp +fi + FDFIXH=${DIRNAME}/fdfixh.sed -OUTPUT_FILE=${HOUT} -INTRO_MESSAGE +OUTPUT_FILE=${HOUT}; INTRO_MESSAGE -sed -f $FDFIXH < $HIN >> ${HOUT} +sed -f ${FDFIXH} < ${HIN} >> ${HOUT} +rm -f ${EXTERN_FUNCS} # Patch the .h file if a patch exists if [ -f "${HPATCH}" ] ; then @@ -104,10 +120,8 @@ FINAL_COUT=${BASENAME}.C FDFIXC=${DIRNAME}/fdfixc.sed -OUTPUT_FILE=${COUT} -INTRO_MESSAGE +OUTPUT_FILE=${COUT}; INTRO_MESSAGE -echo >> ${COUT} echo "#include " >> ${COUT} echo "#include \"forms_gettext.h\"" >> ${COUT} echo "#include \"gettext.h\"" >> ${COUT} @@ -117,14 +131,12 @@ if [ $? -eq 0 ]; then echo "#include \"bmtable.h\"" >> ${COUT} fi -echo >> ${COUT} - sed -f ${FDFIXC} < ${CIN} >> ${COUT} # Patch the .C file if a patch exists -if [ -f "$CPATCH" ] ; then - echo "Patching ${COUT} with $CPATCH" - patch -s ${COUT} < $CPATCH +if [ -f "${CPATCH}" ] ; then + echo "Patching ${COUT} with ${CPATCH}" + patch -s ${COUT} < ${CPATCH} fi # Clean up, to leave the finished .C file diff --git a/src/frontends/xforms/forms/fdfixh.sed b/src/frontends/xforms/forms/fdfixh.sed index 1fb3649ef8..93e80dc24d 100644 --- a/src/frontends/xforms/forms/fdfixh.sed +++ b/src/frontends/xforms/forms/fdfixh.sed @@ -12,36 +12,45 @@ # It contains the instructions that sed requires to manipulate # the .h files produced by fdesign into a form usable by LyX -# Strip multiple blank lines, leaving only one -/^$/{ -N -/^\n$/D -} - -# Rewrite FD_form_xxx as FD_xxx -# This is done both for the structs and for the #define bounding the header -s/\(.*\) FD_form_\(.*\)/\1 FD_\2/ +# Remove trailing whitespace. +s/[ ]*$// -# Forward declare FL_FORM and FL_OBJECT -/#define FD/a\ -\ -#include "forms_fwd.h" -# Delete the fdesign comments +# Delete blank lines, "extern void" function declarations and fdesign comments. +/^$/d +/^extern void/d +/Forms and Objects/d /Callbacks, globals/d /generated with fdesign/d -/Forms and Objects/d -# Replace lines such as "extern void func(args);" -# with "extern "C" void func(args);" -# Note that these should not occur because we should be using signals. See the -# README file for further information. -s/\(extern \)\(void \)\(.*\)/\1 "C" \2\3/ -# Rename the function create_form_form_xxx(void) as build_xxx(void * parent) -s/extern \(.*\) create_form_form_\(.*\)\([(]void[)]\)/\1 build_\2(void *)/ +# Pretty formatting; add an empty line before "#endif" +/#endif/i\ + + +# Immediately after line "#define FD_xxx_h_" that starts off the header file, +# forward declare FL_FORM and FL_OBJECT and append the contents of file +# "extern.tmp". This latter is a sorted, unique list of any function +# declarations. +/#define FD/{ +a\ +\ +#include "forms_fwd.h"\ + +r extern.tmp +} + + +# Rewrite FD_form_xxx as FD_xxx. +# This is done both for the structs and for the #define bounding the header. +s/\(.*\) FD_form_\(.*\)/\1 FD_\2/ + + +# Rename the function create_form_form_xxx(void) as build_xxx(void *). +s/extern \(.*\) create_form_form_\(.*\)[(]void[)]/\1 build_\2(void *)/ -# Manipulate the structs + +# Manipulate the structs: # # Rewrite as # typedef struct { struct FD_xxx { @@ -64,32 +73,27 @@ s/extern \(.*\) create_form_form_\(.*\)\([(]void[)]\)/\1 build_\2(void *)/ # Place all lines containing FL_FORM and FL_OBJECT in the hold space, deleting # them from the pattern space. -# For all lines containing FL_FORM... -/FL_FORM/{ +# For all lines starting with FL_FORM... +/^ FL_FORM/{ -# Rewrite "FL_FORM *form_xxx;" as "FL_FORM * form; -# Note that the spaces before FL_FORM are replaced with a -s/\(.*\)FL_FORM \(.*\)/ FL_FORM * form;/ +# 1. Rewrite "FL_FORM *form_xxx;" as "FL_FORM * form; +s/FL_FORM[ ]*\*form.*/FL_FORM * form;/ -# We know that FL_FORM comes before any FL_OBJECT, so can initialise -# the hold space with it. +# 2. We know that FL_FORM comes before any FL_OBJECT, so can initialise +# the hold space with it. Delete from the pattern space. h d - } -# For all lines containing FL_OBJECT and not containing extern... -/FL_OBJECT/{ -/extern/!{ +# For all lines starting with FL_OBJECT... +/^ FL_OBJECT/{ -# perform a little pretty formatting -s/\(.*\)FL_OBJECT \([*]\)\(.*\)/ FL_OBJECT * \3/ +# 1. Perform a little pretty formatting. +s/FL_OBJECT \*\(.*\)/FL_OBJECT * \1/ -# append to the hold space +# 2. Append to the hold space and delete from the pattern space. H d - -} } # The struct is ended by "} FD_xxx;", so now's the time to paste back the @@ -102,10 +106,11 @@ i\ s/} \(.*\);/struct \1 {\ ~\1();/ -# 3. Paste the contents of the hold space beneath it +# 3. Paste the contents of the hold space beneath it. G -# 4. Close the struct +# 4. Close the struct and append an empty line. a\ -}; +};\ + } -- 2.39.2