]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/forms/fdfix.sh
Yet more dialog tweaking from Rob.
[lyx.git] / src / frontends / xforms / forms / fdfix.sh
1 #!/bin/sh
2 #
3 # file fdfix.sh
4 # This file is part of LyX, the document processor.
5 # Licence details can be found in the file COPYING.
6 #
7 # author Angus Leeming
8 #
9 # Full author contact details are available in file CREDITS
10 #
11 # This shell script takes the dialog created with fdesign and generates the
12 # .C and .h files used by LyX from it.
13 # Note that the REAL magic is to be found in the sed scripts fdfixc.sed and
14 # fdfixh.sed used by this shell script.
15
16 INTRO_MESSAGE ()
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 // This file is part of LyX, the document processor.
31 // Licence details can be found in 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 if [ $? -ne 0 ]; then
56     echo "\"${FDESIGN} -convert ${FDFILE}\" failed. Please investigate."
57     exit 1
58 fi
59
60 #==================================
61 # Modify the .h file for use by LyX
62 HIN=${DIRNAME}/${BASENAME}.h
63 HPATCH=${DIRNAME}/${BASENAME}.h.patch
64 HOUT=${BASENAME}.hpp
65
66 FDFIXH=${DIRNAME}/fdfixh.sed
67
68 OUTPUT_FILE=${HOUT}
69 INTRO_MESSAGE
70
71 sed -f $FDFIXH < $HIN >> ${HOUT}
72
73 # Patch the .h file if a patch exists
74 if [ -f "${HPATCH}" ] ; then
75     echo "Patching ${HOUT} with ${HPATCH}"
76     patch -s ${HOUT} < ${HPATCH}
77 fi
78
79 # Clean up, to leave the finished .h file. We can be a little tricky here
80 # testing to see if the finished file exists already and if it does
81 # testing whether there are any differences.
82 # If there are no differences, then don't overwrite to prevent unnecessary
83 # compilation in the xforms directory.
84 rm -f ${HIN}
85 MOVE_H_FILE=1
86 if [ -r ${BASENAME}.h ]; then
87     cmp -s ${HOUT} ${BASENAME}.h
88     if [ $? -eq 0 ]; then
89         MOVE_H_FILE=0
90     fi
91 fi
92 if [ ${MOVE_H_FILE} -eq 1 ]; then
93     mv ${HOUT} ${BASENAME}.h
94 else
95     rm -f ${HOUT}
96 fi
97
98 #==================================
99 # Create the .C file for use by LyX
100 CIN=${DIRNAME}/${BASENAME}.c
101 CPATCH=${DIRNAME}/${BASENAME}.C.patch
102 COUT=${BASENAME}.cpp
103 FINAL_COUT=${BASENAME}.C
104
105 FDFIXC=${DIRNAME}/fdfixc.sed
106
107 OUTPUT_FILE=${COUT}
108 INTRO_MESSAGE
109
110 echo >> ${COUT}
111 echo "#include <config.h>" >> ${COUT}
112 echo "#include \"forms_gettext.h\"" >> ${COUT}
113 echo "#include \"gettext.h\"" >> ${COUT}
114
115 grep bmtable ${CIN} > /dev/null
116 if [ $? -eq 0 ]; then
117     echo "#include \"bmtable.h\"" >> ${COUT}
118 fi
119
120 # This is (I hope) a very temporary fudge.
121 # FormMathsPanel should be modified in input() to not use the data parameter.
122 # Instead, use the FL_OBJECT * parameter.
123 # Angus 12 June, 2002.
124 grep MM_ ${CIN} > /dev/null
125 if [ $? -eq 0 ]; then
126     echo "#include \"MathsCallbacks.h\"" >> ${COUT}
127 fi
128
129 echo >> ${COUT}
130
131 sed -f ${FDFIXC} < ${CIN} >> ${COUT}
132
133 # Patch the .C file if a patch exists
134 if [ -f "$CPATCH" ] ; then
135     echo "Patching ${COUT} with $CPATCH"
136     patch -s ${COUT} < $CPATCH
137 fi
138
139 # Clean up, to leave the finished .C file
140 rm -f ${CIN}
141 mv ${COUT} ${FINAL_COUT}
142
143 #========================================