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 if [ $1 = ${BASENAME} ]; then
51 echo "Input file is not a .fd file. Cannot continue"
55 #===================================
56 # Create the initial .c and .h files
60 (cd ${DIRNAME} && ${FDESIGN} -convert ${FDFILE}) ||
62 echo "\"${FDESIGN} -convert ${FDFILE}}\" failed. Please investigate."
66 #==================================
67 # Modify the .h file for use by LyX
68 HIN=${DIRNAME}/${BASENAME}.h
69 HPATCH=${DIRNAME}/${BASENAME}.h.patch
72 # First clean up the "extern void func(arg);" declarations and
73 # put the sorted, unique list in file ${EXTERN_FUNCS}
74 # The contents of this file are used by ${FDFIXH} to replace the mess
76 # Note that we use unique file names for temp files to enable re-entrant
77 # builds with SMP machines
78 EXTERN_FUNCS=extern.$$
79 sed -n 's/extern void \(.*\)/void \1/p' ${HIN} > ${EXTERN_FUNCS}
81 if [ -s ${EXTERN_FUNCS} ]; then
83 sort -u ${EXTERN_FUNCS} > ${TMP}
84 echo "extern \"C\" {" > ${EXTERN_FUNCS}
85 cat ${TMP} >> ${EXTERN_FUNCS}
86 echo "}" >> ${EXTERN_FUNCS}
90 # First ensure that the sed script knows where to find ${EXTERN_FUNCS}
92 sed "s/EXTERN_FUNCS/${EXTERN_FUNCS}/" ${DIRNAME}/fdfixh.sed > ${FDFIXH}
96 sed -f ${FDFIXH} < ${HIN} >> ${HOUT}
98 # Don't forget to clean up the temporary files.
99 rm -f ${EXTERN_FUNCS} ${FDFIXH}
101 # Patch the .h file if a patch exists
102 if [ -f "${HPATCH}" ] ; then
103 echo "Patching ${HOUT} with ${HPATCH}"
104 patch -s ${HOUT} < ${HPATCH}
107 # Clean up, to leave the finished .h file. We can be a little tricky here
108 # testing to see if the finished file exists already and if it does
109 # testing whether there are any differences.
110 # If there are no differences, then don't overwrite to prevent unnecessary
111 # compilation in the xforms directory.
114 if [ -r ${BASENAME}.h ]; then
115 cmp -s ${HOUT} ${BASENAME}.h && MOVE_H_FILE=0
118 if [ ${MOVE_H_FILE} -eq 1 ]; then
119 mv ${HOUT} ${BASENAME}.h
124 #==================================
125 # Create the .C file for use by LyX
126 CIN=${DIRNAME}/${BASENAME}.c
127 CPATCH=${DIRNAME}/${BASENAME}.C.patch
129 FINAL_COUT=${BASENAME}.C
131 # We use a two pass algorithm to generate elegant C++ code whilst
132 # keeping the sed clean also.
134 # Pass 1. The bulk of the clean-up
135 FDFIXC=${DIRNAME}/fdfixc.sed
140 echo "#include <config.h>" >> ${TMP}
141 echo "#include \"forms_gettext.h\"" >> ${TMP}
142 echo "#include \"gettext.h\"" >> ${TMP}
144 grep bmtable ${CIN} > /dev/null &&
145 echo "#include \"bmtable.h\"" >> ${TMP}
147 sed -f ${FDFIXC} < ${CIN} >> ${TMP}
149 # Pass 2. Ensure that any c_str variables inserted by fdfixc.sed
150 # are declared at the top of the appropriate function.
151 FDFIXC=${DIRNAME}/c_str.sed
152 sed -f ${FDFIXC} < ${TMP} > ${COUT}
155 if [ -f "${CPATCH}" ] ; then
156 echo "Patching ${COUT} with ${CPATCH}"
157 patch -s ${COUT} < ${CPATCH}
160 # Clean up, to leave the finished .C file
162 mv ${COUT} ${FINAL_COUT}
164 #========================================