]> git.lyx.org Git - lyx.git/blob - 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
1  #! /bin/sh
2 #
3 # \file fdfix.sh
4 # Copyright 2002 the LyX Team
5 # Read the file COPYING
6 #
7 # \author Angus Leeming, leeming@lyx.org
8 #
9 # This shell script takes the dialog created with fdesign and generates the
10 # .C and .h files used by LyX from it.
11 # Note that the REAL magic is to be found in the sed scripts fdfixc.sed and
12 # fdfixh.sed used by this shell script.
13
14 INTRO_MESSAGE ()
15 {
16 DATE=`date +"%Y"`
17
18 # Note that we can't create a variable containing this and then
19 # echo it across because some machines require -e to recognize \n et al.
20 # Other machines, of course output -e, it not being an option they
21 # recognise ;-)
22
23 # Set ${OUTPUT_FILE} to ${HOUT} or ${COUT} as appropriate
24 cat - > ${OUTPUT_FILE} <<EOF
25 // File generated by fdesign from ${FDFILE}
26 // and modified by fdfix.sh for use by LyX.
27
28 // WARNING! All changes made to this file will be lost!
29
30 // Copyright $DATE the LyX Team
31 // Read the file COPYING
32 EOF
33 }
34
35 #===============
36 # Initial checks
37 if [ ! -f $1 ]; then
38     echo "Input file does not exist. Cannot continue"
39     exit 1
40 fi
41
42 DIRNAME=`dirname $1`
43 BASENAME=`basename $1 .fd`
44
45 if [ $1 = ${BASENAME} ]; then
46     echo "Input file is not a .fd file. Cannot continue"
47     exit 1
48 fi
49
50 #===================================
51 # Create the initial .c and .h files
52 FDESIGN=fdesign
53 FDFILE=${BASENAME}.fd
54 (cd ${DIRNAME}; ${FDESIGN} -convert ${FDFILE})
55
56 #==================================
57 # Modify the .h file for use by LyX
58 HIN=${DIRNAME}/${BASENAME}.h
59 HPATCH=${DIRNAME}/${BASENAME}.h.patch
60 HOUT=${BASENAME}.H
61
62 FDFIXH=${DIRNAME}/fdfixh.sed
63
64 OUTPUT_FILE=${HOUT}
65 INTRO_MESSAGE
66
67 sed -f $FDFIXH < $HIN >> ${HOUT}
68
69 # Patch the .h file if a patch exists
70 if [ -f "${HPATCH}" ] ; then
71     echo "Patching ${HOUT} with ${HPATCH}"
72     patch -s ${HOUT} < ${HPATCH}
73 fi
74
75 # Clean up, to leave the finished .h file
76 rm -f ${HIN}
77 mv ${HOUT} ${BASENAME}.h
78
79 #==================================
80 # Create the .C file for use by LyX
81 CIN=${DIRNAME}/${BASENAME}.c
82 CPATCH=${DIRNAME}/${BASENAME}.C.patch
83 COUT=${BASENAME}.C
84
85 FDFIXC=${DIRNAME}/fdfixc.sed
86
87 OUTPUT_FILE=${COUT}
88 INTRO_MESSAGE
89
90 echo >> ${COUT}
91 echo "#include <config.h>" >> ${COUT}
92 echo "#include \"forms_gettext.h\"" >> ${COUT}
93 echo "#include \"gettext.h\"" >> ${COUT}
94
95 grep bmtable ${CIN} > /dev/null
96 if [ $? -eq 0 ]; then
97     echo "#include \"bmtable.h\"" >> ${COUT}
98 fi
99
100 # This is (I hope) a very temporary fudge.
101 # FormMathsPanel should be modified in input() to not use the data parameter.
102 # Instead, use the FL_OBJECT * parameter.
103 # Angus 12 June, 2002.
104 grep MM_ ${CIN} > /dev/null
105 if [ $? -eq 0 ]; then
106     echo "#include \"MathsSymbols.h\"" >> ${COUT}
107 fi
108
109 echo >> ${COUT}
110
111 sed -f ${FDFIXC} < ${CIN} >> ${COUT}
112
113 # Patch the .C file if a patch exists
114 if [ -f "$CPATCH" ] ; then
115     echo "Patching ${COUT} with $CPATCH"
116     patch -s ${COUT} < $CPATCH
117 fi
118
119 # Clean up, to leave the finished .C file
120 rm -f ${CIN}
121
122 #========================================