]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/xforms/forms/fdfix.sh
xforms clean-up, described in detail in my mail of 31 May. See
[lyx.git] / src / frontends / xforms / forms / fdfix.sh
index e788b620b4188d7a227750a07655c81a96365243..6a4d143dc8fb924c9d531867b2860ae268a52541 100644 (file)
-#! /bin/sh -x
+ #! /bin/sh
 #
-# NOTE: This is NOT the same fdfix.sh as in ${top_srcdir}/forms
-#       It is a modified version to suit use for gui-indep.
+# \file fdfix.sh
+# Copyright 2002 the LyX Team
+# Read the file COPYING
 #
+# \author Angus Leeming, leeming@lyx.org
+#
+# This shell script takes the dialog created with fdesign and generates the
+# .C and .h files used by LyX from it.
+# Note that the REAL magic is to be found in the sed scripts fdfixc.sed and
+# fdfixh.sed used by this shell script.
+
+INTRO_MESSAGE ()
+{
+DATE=`date +"%Y"`
+
+# Note that we can't create a variable containing this and then
+# echo it across because some machines require -e to recognize \n et al.
+# Other machines, of course output -e, it not being an option they
+# recognise ;-)
+
+# Set ${OUTPUT_FILE} to ${HOUT} or ${COUT} as appropriate
+cat - > ${OUTPUT_FILE} <<EOF
+// File generated by fdesign from ${FDFILE}
+// and modified by fdfix.sh for use by LyX.
+
+// WARNING! All changes made to this file will be lost!
+
+// Copyright $DATE the LyX Team
+// Read the file COPYING
+EOF
+}
 
+#===============
+# Initial checks
 if [ ! -f $1 ]; then
     echo "Input file does not exist. Cannot continue"
     exit 1
 fi
 
-FDESIGN=fdesign
-
-# names of the files generated by fdesign and by running the sed scripts
-BASE=`basename $1 .fd`
+DIRNAME=`dirname $1`
+BASENAME=`basename $1 .fd`
 
-if [ $1 = $BASE ]; then
+if [ $1 = ${BASENAME} ]; then
     echo "Input file is not a .fd file. Cannot continue"
     exit 1
 fi
 
-CIN=$BASE.c
-COUT=$BASE.C
-HIN=$BASE.h
-HOUT=$BASE.H
-
-# Ascertain the class name from the name of the file
-# eg form_my_new_dialog -> FormMyNewDialog
-CLASSNAME=""
-SECTION="start"
-i=1
-while :
-do
-    SECTION=`echo $BASE | cut -d_ -f$i`
-    i=`expr $i + 1 `
-
-    if [ $SECTION ]
-    then
-       FIRST=`echo $SECTION | cut -c1 | tr a-z A-Z`
-       SECOND=`echo $SECTION | cut -c2-`
-       CLASSNAME=$CLASSNAME$FIRST$SECOND
-    else
-       break
-    fi
-done
-
-# Create .c and .h files
-$FDESIGN -convert $1
-FDFIXH=fdfixh.sed
-FDFIXC=fdfixc.sed
-FDFIXC_MOD=fdfixc_modified.sed
-
-# Modify .h file for use by LyX
-echo "// File modified by fdfix.sh for use by lyx (with xforms >= 0.88) and gettext" > $HOUT
-sed -f $FDFIXH < $HIN >> $HOUT
+#===================================
+# Create the initial .c and .h files
+FDESIGN=fdesign
+FDFILE=${BASENAME}.fd
+(cd ${DIRNAME}; ${FDESIGN} -convert ${FDFILE})
+
+#==================================
+# Modify the .h file for use by LyX
+HIN=${DIRNAME}/${BASENAME}.h
+HPATCH=${DIRNAME}/${BASENAME}.h.patch
+HOUT=${BASENAME}.H
+
+FDFIXH=${DIRNAME}/fdfixh.sed
+
+OUTPUT_FILE=${HOUT}
+INTRO_MESSAGE
+
+sed -f $FDFIXH < $HIN >> ${HOUT}
 
 # Patch the .h file if a patch exists
-if [ -f "$HOUT.patch" ] ; then
-    echo "Patching $HOUT with $HOUT.patch"
-    patch -s $HOUT < $HOUT.patch
+if [ -f "${HPATCH}" ] ; then
+    echo "Patching ${HOUT} with ${HPATCH}"
+    patch -s ${HOUT} < ${HPATCH}
 fi
 
-# Modify the .c file sed-script
-# (Quicker to modify the sed script than the .c file!)
-sed -e "s/CLASSNAME/$CLASSNAME/" < $FDFIXC > $FDFIXC_MOD
-
-# Modify .c file for use by LyX
-echo "// File modified by fdfix.sh for use by lyx (with xforms >= 0.88) and gettext" > $COUT
-echo "#include <config.h>" >> $COUT
-echo "#include \"lyx_gui_misc.h\"" >> $COUT
-echo "#include \"gettext.h\"" >> $COUT
-echo >> $COUT
-
-sed -f $FDFIXC_MOD < $CIN >> $COUT
-
-# hack for file dialog
-if [ "$CLASSNAME" = "FormFiledialog" ] ; then
-    ed $COUT >/dev/null 2>/dev/null << EOF
-/FormFiledialog::build_filedialog
-s/FormFiledialog/FileDialog::Private/
-wq
-EOF
+# Clean up, to leave the finished .h file
+rm -f ${HIN}
+mv ${HOUT} ${BASENAME}.h
+
+#==================================
+# Create the .C file for use by LyX
+CIN=${DIRNAME}/${BASENAME}.c
+CPATCH=${DIRNAME}/${BASENAME}.C.patch
+COUT=${BASENAME}.C
+
+FDFIXC=${DIRNAME}/fdfixc.sed
+
+OUTPUT_FILE=${COUT}
+INTRO_MESSAGE
+
+echo >> ${COUT}
+echo "#include <config.h>" >> ${COUT}
+echo "#include \"forms_gettext.h\"" >> ${COUT}
+echo "#include \"gettext.h\"" >> ${COUT}
+
+grep bmtable ${CIN} > /dev/null
+if [ $? -eq 0 ]; then
+    echo "#include \"bmtable.h\"" >> ${COUT}
+fi
+
+# This is (I hope) a very temporary fudge.
+# FormMathsPanel should be modified in input() to not use the data parameter.
+# Instead, use the FL_OBJECT * parameter.
+# Angus 12 June, 2002.
+grep MM_ ${CIN} > /dev/null
+if [ $? -eq 0 ]; then
+    echo "#include \"MathsSymbols.h\"" >> ${COUT}
 fi
 
+echo >> ${COUT}
+
+sed -f ${FDFIXC} < ${CIN} >> ${COUT}
+
 # Patch the .C file if a patch exists
-if [ -f "$COUT.patch" ] ; then
-    echo "Patching $COUT with $COUT.patch"
-    patch -s $COUT < $COUT.patch
+if [ -f "$CPATCH" ] ; then
+    echo "Patching ${COUT} with $CPATCH"
+    patch -s ${COUT} < $CPATCH
 fi
 
-# Clean up, to leave .C and .h files
-rm -f $CIN $HIN $FDFIXC_MOD
-mv $HOUT $HIN
+# Clean up, to leave the finished .C file
+rm -f ${CIN}
+
+#========================================