4 # This file is part of LyX, the document processor.
5 # Licence details can be found in the file COPYING.
9 # Full author contact details are available in file CREDITS
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.
19 echo "Expected a file name!"
23 # Note that we can't create a variable containing this and then
24 # echo it across because some machines require -e to recognize \n et al.
25 # Other machines, of course output -e, it not being an option they
29 // File generated by fdesign from ${FDFILE}
30 // and modified by fdfix.sh for use by LyX.
32 // WARNING! All changes made to this file will be lost!
34 // This file is part of LyX, the document processor.
35 // Licence details can be found in the file COPYING.
43 echo "Input file does not exist. Cannot continue"
48 BASENAME=`basename $1 .fd`
50 FDFIXH_SED=`dirname $0`/fdfixh.sed
51 FDFIXC_SED=`dirname $0`/fdfixc.sed
52 TMP_STR_SED=`dirname $0`/tmp_str.sed
54 if [ $1 = ${BASENAME} ]; then
55 echo "Input file is not a .fd file. Cannot continue"
59 #===================================
60 # Create the initial .c and .h files
64 (cd ${DIRNAME} && ${FDESIGN} -convert ${FDFILE}) ||
66 echo "\"${FDESIGN} -convert ${FDFILE}}\" failed. Please investigate."
70 #==================================
71 # Modify the .h file for use by LyX
72 HIN=${DIRNAME}/${BASENAME}.h
73 HPATCH=${DIRNAME}/${BASENAME}.h.patch
76 # First clean up the "extern void func(arg);" declarations and
77 # put the sorted, unique list in file ${EXTERN_FUNCS}
78 # The contents of this file are used by ${FDFIXH} to replace the mess
80 # Note that we use unique file names for temp files to enable re-entrant
81 # builds with SMP machines
82 EXTERN_FUNCS=extern.$$
83 sed -n 's/extern void \(.*\)/void \1/p' ${HIN} > ${EXTERN_FUNCS}
85 if [ -s ${EXTERN_FUNCS} ]; then
87 sort -u ${EXTERN_FUNCS} > ${TMP}
88 echo "extern \"C\" {" > ${EXTERN_FUNCS}
89 cat ${TMP} >> ${EXTERN_FUNCS}
90 echo "}" >> ${EXTERN_FUNCS}
94 # First ensure that the sed script knows where to find ${EXTERN_FUNCS}
96 sed "s/EXTERN_FUNCS/${EXTERN_FUNCS}/" ${FDFIXH_SED} > ${FDFIXH}
100 sed -f ${FDFIXH} < ${HIN} >> ${HOUT}
102 # Don't forget to clean up the temporary files.
103 rm -f ${EXTERN_FUNCS} ${FDFIXH}
105 # Patch the .h file if a patch exists
106 if [ -f "${HPATCH}" ] ; then
107 echo "Patching ${HOUT} with ${HPATCH}"
108 patch -s ${HOUT} < ${HPATCH}
111 # Clean up, to leave the finished .h file. We can be a little tricky here
112 # testing to see if the finished file exists already and if it does
113 # testing whether there are any differences.
114 # If there are no differences, then don't overwrite to prevent unnecessary
115 # compilation in the xforms directory.
118 if [ -r ${BASENAME}.h ]; then
119 cmp -s ${HOUT} ${BASENAME}.h && MOVE_H_FILE=0
122 if [ ${MOVE_H_FILE} -eq 1 ]; then
123 mv ${HOUT} ${BASENAME}.h
128 #==================================
129 # Create the .C file for use by LyX
130 CIN=${DIRNAME}/${BASENAME}.c
131 CPATCH=${DIRNAME}/${BASENAME}.C.patch
133 FINAL_COUT=${BASENAME}.C
135 # We use a two pass algorithm to generate elegant C++ code whilst
136 # keeping the sed clean also.
138 # Pass 1. The bulk of the clean-up
142 echo "#include <config.h>" >> ${TMP}
143 echo "#include \"forms_gettext.h\"" >> ${TMP}
144 echo "#include \"gettext.h\"" >> ${TMP}
145 echo "#include \"../lyx_forms.h\"" >> ${TMP}
146 grep bmtable ${CIN} > /dev/null &&
147 echo "#include \"bmtable.h\"" >> ${TMP}
148 grep combox ${CIN} > /dev/null &&
149 echo "#include \"combox.h\"" >> ${TMP}
150 echo "using std::string;" >> ${TMP}
152 sed -f ${FDFIXC_SED} < ${CIN} >> ${TMP}
154 # Pass 2. Ensure that any tmp_str variables inserted by fdfixc.sed
155 # are declared at the top of the appropriate function.
156 sed -f ${TMP_STR_SED} < ${TMP} > ${COUT}
159 if [ -f "${CPATCH}" ] ; then
160 echo "Patching ${COUT} with ${CPATCH}"
161 patch -s ${COUT} < ${CPATCH}
164 # Clean up, to leave the finished .C file
166 mv ${COUT} ${FINAL_COUT}
168 #========================================