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.
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
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.
28 // WARNING! All changes made to this file will be lost!
30 // This file is part of LyX, the document processor.
31 // Licence details can be found in the file COPYING.
39 echo "Input file does not exist. Cannot continue"
44 BASENAME=`basename $1 .fd`
46 if [ $1 = ${BASENAME} ]; then
47 echo "Input file is not a .fd file. Cannot continue"
51 #===================================
52 # Create the initial .c and .h files
55 (cd ${DIRNAME} && ${FDESIGN} -convert ${FDFILE})
57 echo "\"${FDESIGN} -convert ${FDFILE}\" failed. Please investigate."
61 #==================================
62 # Modify the .h file for use by LyX
63 HIN=${DIRNAME}/${BASENAME}.h
64 HPATCH=${DIRNAME}/${BASENAME}.h.patch
67 # First clean up the "extern void func(arg);" declarations and
68 # put the sorted, unique list in file ${EXTERN_FUNCS}
69 # The contents of this file are used by ${FDFIXH} to replace the mess
71 EXTERN_FUNCS=extern.tmp
72 sed -n 's/extern void \(.*\)/void \1/p' ${HIN} > ${EXTERN_FUNCS}
74 if [ -s ${EXTERN_FUNCS} ]; then
75 sort -u ${EXTERN_FUNCS} > tmp
76 echo "extern \"C\" {" > ${EXTERN_FUNCS}
77 cat tmp >> ${EXTERN_FUNCS}
78 echo "}" >> ${EXTERN_FUNCS}
82 FDFIXH=${DIRNAME}/fdfixh.sed
84 OUTPUT_FILE=${HOUT}; INTRO_MESSAGE
86 sed -f ${FDFIXH} < ${HIN} >> ${HOUT}
89 # Patch the .h file if a patch exists
90 if [ -f "${HPATCH}" ] ; then
91 echo "Patching ${HOUT} with ${HPATCH}"
92 patch -s ${HOUT} < ${HPATCH}
95 # Clean up, to leave the finished .h file. We can be a little tricky here
96 # testing to see if the finished file exists already and if it does
97 # testing whether there are any differences.
98 # If there are no differences, then don't overwrite to prevent unnecessary
99 # compilation in the xforms directory.
102 if [ -r ${BASENAME}.h ]; then
103 cmp -s ${HOUT} ${BASENAME}.h
104 if [ $? -eq 0 ]; then
108 if [ ${MOVE_H_FILE} -eq 1 ]; then
109 mv ${HOUT} ${BASENAME}.h
114 #==================================
115 # Create the .C file for use by LyX
116 CIN=${DIRNAME}/${BASENAME}.c
117 CPATCH=${DIRNAME}/${BASENAME}.C.patch
119 FINAL_COUT=${BASENAME}.C
121 FDFIXC=${DIRNAME}/fdfixc.sed
123 OUTPUT_FILE=${COUT}; INTRO_MESSAGE
125 echo "#include <config.h>" >> ${COUT}
126 echo "#include \"forms_gettext.h\"" >> ${COUT}
127 echo "#include \"gettext.h\"" >> ${COUT}
129 grep bmtable ${CIN} > /dev/null
130 if [ $? -eq 0 ]; then
131 echo "#include \"bmtable.h\"" >> ${COUT}
134 sed -f ${FDFIXC} < ${CIN} >> ${COUT}
136 # Patch the .C file if a patch exists
137 if [ -f "${CPATCH}" ] ; then
138 echo "Patching ${COUT} with ${CPATCH}"
139 patch -s ${COUT} < ${CPATCH}
142 # Clean up, to leave the finished .C file
144 mv ${COUT} ${FINAL_COUT}
146 #========================================