]> 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 4b86724cf231db25cb3c94ff844553ecd6489263..6a4d143dc8fb924c9d531867b2860ae268a52541 100644 (file)
-#! /bin/sh
+ #! /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
 #
-if [ "$1" = "$2" ]; then
-    echo "Input and Output file can not be the same."
+# \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
 
-if [ -f $2 ]; then
-       echo "Output file already exists, overwrite?"
-       read
-       if [ "$REPLY" != "y" ]; then
-           exit 0
-       fi
-fi
+DIRNAME=`dirname $1`
+BASENAME=`basename $1 .fd`
 
-if [ ! -f $1 ]; then
-    echo "Input file does not exist, can not continue"
+if [ $1 = ${BASENAME} ]; then
+    echo "Input file is not a .fd file. Cannot continue"
     exit 1
 fi
 
-# If there is a patch for the inputfile patch the input file with it.
-if [ -f "$1.patch" ]; then
-    echo "Patching $1 with $1.patch"
-    patch -s $1 < "$1.patch"
+#===================================
+# 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 "${HPATCH}" ] ; then
+    echo "Patching ${HOUT} with ${HPATCH}"
+    patch -s ${HOUT} < ${HPATCH}
 fi
 
-echo "// File modified by fdfix.sh for use by lyx (with xforms >= 0.88) and gettext" > $2
-echo "#include <config.h>" >> $2
-echo "#include \"lyx_gui_misc.h\"" >> $2
-echo "#include \"gettext.h\"" >> $2
-echo >> $2
+# Clean up, to leave the finished .h file
+rm -f ${HIN}
+mv ${HOUT} ${BASENAME}.h
 
-# The commands to sed does this:
-#
-# -e 's/#include \"forms\.h\"/#include FORMS_H_LOCATION/'
-#
-#  Replace "forms.h" by FORMS_H_LOCATION in #include directives. This
-#  macro is defined in config.h and is either <forms.h> or
-#  <X11/forms.h>. 
-#
-#  -e "/#include \"form_.*\"/a\\
-#  #include \"$classname.h\" "
-#
-#   For all lines containing "#include "form_*"", append a line
-#   containing the header file of the parent class
-#
-# -e '/fl_/ s/".[^|]*"/_(&)/'
-#  
-#  For all lines containing "fl_" and a string _not_ containing |,
-#  replace the string with _(string)
-#
-# -e '/shortcut/ s/".*[|].*"/scex(_(&))/'
-#
-#  For all lines containing "shortcut" and a string containing |, replace
-#  the string with scex(_(string))
-#
-# -e '/fl_add/ s/".*[|].*"/idex(_(&))/'
-#
-#  For all lines containing "fl_add" and a string containing |, replace
-#  the string with idex(_(string))
-#
-# -e '/fl_add/ s/idex("\(.*\)").*$/&\
-#     fl_set_button_shortcut(obj,"\1",1);/'
-#
-# For all lines containing "fl_add" and a string containing |, add the
-# shortcut command after the end of this line
-#
-# -e 's/\(\(FD_[^ ]*\) \*fdui =\).*sizeof(\*fdui))/\1 new \2/'
-#
-# We use new/delete not malloc/free so change to suit.
-#
-# -e "s/\(FD_f\([^ _]*\)_\([^ ]*\)\) \*create_form_form[^ ]*/\1 * $classname::build_\3()/"
-#
-# Fixup the name of the create_form... function to have a signature matching
-# that of the method it will become.
-#
-# -e 's/\(fdui->form[^ ]*\)\(.*bgn_form.*\)/\1\2\
-#     \1->u_vdata = this;/' \
-#
-# We need to store a pointer to the dialog in u_vdata so that the callbacks
-# will work.
-#
-# -e 's/,\([^ ]\)/, \1/g'
-#
-# Someone got busy and put spaces in after commas but didn't allow for the
-# autogeneration of the files so their pretty formatting got lost. Not anymore.
-#
+#==================================
+# 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 "$CPATCH" ] ; then
+    echo "Patching ${COUT} with $CPATCH"
+    patch -s ${COUT} < $CPATCH
+fi
+
+# Clean up, to leave the finished .C file
+rm -f ${CIN}
 
-classname=`basename $1 .c | cut -c6-`
-firstchar=`echo $classname | cut -c1 | tr a-z A-Z`
-rest=`echo $classname | cut -c2-`
-classname=Form$firstchar$rest
-export classname
-
-cat $1 | sed \
--e 's/#include \"forms\.h\"/#include FORMS_H_LOCATION/' \
--e "/#include \"form_.*\"/a\\
-#include \"$classname.h\" " \
--e '/fl_/ s/".[^|]*"/_(&)/' \
--e '/shortcut/ s/".*[|].*"/scex(_(&))/' \
--e '/fl_add/ s/".*[|].*"/idex(_(&))/' \
--e '/fl_add/ s/idex(\(.*\)").*$/&\
-    fl_set_button_shortcut(obj,scex(\1")),1);/' \
--e 's/\(\(FD_[^ ]*\) \*fdui =\).*sizeof(\*fdui))/\1 new \2/' \
--e "s/\(FD_f\([^ _]*\)_\([^ ]*\)\) \*create_form_form[^ ]*/\1 * $classname::build_\3()/" \
--e 's/\(fdui->form[^ ]*\)\(.*bgn_form.*\)/\1\2\
-  \1->u_vdata = this;/' \
--e 's/,\([^ ]\)/, \1/g' >> $2
+#========================================