]> git.lyx.org Git - features.git/commitdiff
I reckon that the generated .h files and the scripts that modify them
authorAngus Leeming <leeming@lyx.org>
Thu, 21 Nov 2002 10:58:28 +0000 (10:58 +0000)
committerAngus Leeming <leeming@lyx.org>
Thu, 21 Nov 2002 10:58:28 +0000 (10:58 +0000)
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
src/frontends/xforms/forms/fdfix.sh
src/frontends/xforms/forms/fdfixh.sed

index 54df903bb27b36515915c60739d38059d52cb79a..2654b740cb5749d3d562479928489d45b9d74ef6 100644 (file)
@@ -1,3 +1,9 @@
+2002-11-20  Angus Leeming  <leeming@lyx.org>
+
+       * 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  <leeming@lyx.org>
 
        * MathsCallbacks.h: removed.
index 4e6f8c498438a7a795d228f18d5c42ded407571a..4ed635f5c4d7a55d385fdaa1ab2f808915f71b1e 100644 (file)
@@ -29,6 +29,7 @@ cat - > ${OUTPUT_FILE} <<EOF
 
 // This file is part of LyX, the document processor.
 // Licence details can be found in the file COPYING.
+
 EOF
 }
 
@@ -51,7 +52,7 @@ fi
 # Create the initial .c and .h files
 FDESIGN=fdesign
 FDFILE=${BASENAME}.fd
-(cd ${DIRNAME}; ${FDESIGN} -convert ${FDFILE})
+(cd ${DIRNAME} && ${FDESIGN} -convert ${FDFILE})
 if [ $? -ne 0 ]; then
     echo "\"${FDESIGN} -convert ${FDFILE}\" failed. Please investigate."
     exit 1
@@ -63,12 +64,27 @@ HIN=${DIRNAME}/${BASENAME}.h
 HPATCH=${DIRNAME}/${BASENAME}.h.patch
 HOUT=${BASENAME}.hpp
 
+# First clean up the "extern void func(arg);" declarations and
+# put the sorted, unique list in file ${EXTERN_FUNCS}
+# The contents of this file are used by ${FDFIXH} to replace the mess
+# output by fdesign
+EXTERN_FUNCS=extern.tmp
+sed -n 's/extern void \(.*\)/void \1/p' ${HIN} > ${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 <config.h>" >> ${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
index 1fb3649ef8f411459b1466f0aa824e63e8fdf3e4..93e80dc24d2c9a572d3c6ba4ecc9dd74fef03ded 100644 (file)
 # 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 <tab>
-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\
-};
+};\
+
 }