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
56 (cd ${DIRNAME} && ${FDESIGN} -convert ${FDFILE}) ||
58 echo "\"${FDESIGN} -convert ${FDFILE}}\" failed. Please investigate."
62 #==================================
63 # Modify the .h file for use by LyX
64 HIN=${DIRNAME}/${BASENAME}.h
65 HPATCH=${DIRNAME}/${BASENAME}.h.patch
68 # First clean up the "extern void func(arg);" declarations and
69 # put the sorted, unique list in file ${EXTERN_FUNCS}
70 # The contents of this file are used by ${FDFIXH} to replace the mess
72 EXTERN_FUNCS=extern.tmp
73 sed -n 's/extern void \(.*\)/void \1/p' ${HIN} > ${EXTERN_FUNCS}
75 if [ -s ${EXTERN_FUNCS} ]; then
76 sort -u ${EXTERN_FUNCS} > tmp
77 echo "extern \"C\" {" > ${EXTERN_FUNCS}
78 cat tmp >> ${EXTERN_FUNCS}
79 echo "}" >> ${EXTERN_FUNCS}
83 FDFIXH=${DIRNAME}/fdfixh.sed
85 OUTPUT_FILE=${HOUT}; INTRO_MESSAGE
87 sed -f ${FDFIXH} < ${HIN} >> ${HOUT}
90 # Patch the .h file if a patch exists
91 if [ -f "${HPATCH}" ] ; then
92 echo "Patching ${HOUT} with ${HPATCH}"
93 patch -s ${HOUT} < ${HPATCH}
96 # Clean up, to leave the finished .h file. We can be a little tricky here
97 # testing to see if the finished file exists already and if it does
98 # testing whether there are any differences.
99 # If there are no differences, then don't overwrite to prevent unnecessary
100 # compilation in the xforms directory.
103 if [ -r ${BASENAME}.h ]; then
104 cmp -s ${HOUT} ${BASENAME}.h && MOVE_H_FILE=0
107 if [ ${MOVE_H_FILE} -eq 1 ]; then
108 mv ${HOUT} ${BASENAME}.h
113 #==================================
114 # Create the .C file for use by LyX
115 CIN=${DIRNAME}/${BASENAME}.c
116 CPATCH=${DIRNAME}/${BASENAME}.C.patch
118 FINAL_COUT=${BASENAME}.C
120 FDFIXC=${DIRNAME}/fdfixc.sed
122 OUTPUT_FILE=${COUT}; INTRO_MESSAGE
124 # This "c_str" is potentially used many times in many functions
125 # so add it to the top of the generated file.
126 grep -E 'fl_add.*".*[|].*"' ${CIN} > /dev/null &&
127 cat - >> ${COUT} <<EOF
135 echo "#include <config.h>" >> ${COUT}
136 echo "#include \"forms_gettext.h\"" >> ${COUT}
137 echo "#include \"gettext.h\"" >> ${COUT}
139 grep bmtable ${CIN} > /dev/null &&
140 echo "#include \"bmtable.h\"" >> ${COUT}
142 sed -f ${FDFIXC} < ${CIN} >> ${COUT}
144 # Patch the .C file if a patch exists
145 if [ -f "${CPATCH}" ] ; then
146 echo "Patching ${COUT} with ${CPATCH}"
147 patch -s ${COUT} < ${CPATCH}
150 # Clean up, to leave the finished .C file
152 mv ${COUT} ${FINAL_COUT}
154 #========================================