]> git.lyx.org Git - features.git/blob - src/frontends/xforms/forms/fdfix.sh
I reckon that the generated .h files and the scripts that modify them
[features.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
33 EOF
34 }
35
36 #===============
37 # Initial checks
38 if [ ! -f $1 ]; then
39     echo "Input file does not exist. Cannot continue"
40     exit 1
41 fi
42
43 DIRNAME=`dirname $1`
44 BASENAME=`basename $1 .fd`
45
46 if [ $1 = ${BASENAME} ]; then
47     echo "Input file is not a .fd file. Cannot continue"
48     exit 1
49 fi
50
51 #===================================
52 # Create the initial .c and .h files
53 FDESIGN=fdesign
54 FDFILE=${BASENAME}.fd
55 (cd ${DIRNAME} && ${FDESIGN} -convert ${FDFILE})
56 if [ $? -ne 0 ]; then
57     echo "\"${FDESIGN} -convert ${FDFILE}\" failed. Please investigate."
58     exit 1
59 fi
60
61 #==================================
62 # Modify the .h file for use by LyX
63 HIN=${DIRNAME}/${BASENAME}.h
64 HPATCH=${DIRNAME}/${BASENAME}.h.patch
65 HOUT=${BASENAME}.hpp
66
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
70 # output by fdesign
71 EXTERN_FUNCS=extern.tmp
72 sed -n 's/extern void \(.*\)/void \1/p' ${HIN} > ${EXTERN_FUNCS}
73
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}
79         rm -f tmp
80 fi
81
82 FDFIXH=${DIRNAME}/fdfixh.sed
83
84 OUTPUT_FILE=${HOUT}; INTRO_MESSAGE
85
86 sed -f ${FDFIXH} < ${HIN} >> ${HOUT}
87 rm -f ${EXTERN_FUNCS}
88
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}
93 fi
94
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.
100 rm -f ${HIN}
101 MOVE_H_FILE=1
102 if [ -r ${BASENAME}.h ]; then
103     cmp -s ${HOUT} ${BASENAME}.h
104     if [ $? -eq 0 ]; then
105         MOVE_H_FILE=0
106     fi
107 fi
108 if [ ${MOVE_H_FILE} -eq 1 ]; then
109     mv ${HOUT} ${BASENAME}.h
110 else
111     rm -f ${HOUT}
112 fi
113
114 #==================================
115 # Create the .C file for use by LyX
116 CIN=${DIRNAME}/${BASENAME}.c
117 CPATCH=${DIRNAME}/${BASENAME}.C.patch
118 COUT=${BASENAME}.cpp
119 FINAL_COUT=${BASENAME}.C
120
121 FDFIXC=${DIRNAME}/fdfixc.sed
122
123 OUTPUT_FILE=${COUT}; INTRO_MESSAGE
124
125 echo "#include <config.h>" >> ${COUT}
126 echo "#include \"forms_gettext.h\"" >> ${COUT}
127 echo "#include \"gettext.h\"" >> ${COUT}
128
129 grep bmtable ${CIN} > /dev/null
130 if [ $? -eq 0 ]; then
131     echo "#include \"bmtable.h\"" >> ${COUT}
132 fi
133
134 sed -f ${FDFIXC} < ${CIN} >> ${COUT}
135
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}
140 fi
141
142 # Clean up, to leave the finished .C file
143 rm -f ${CIN}
144 mv ${COUT} ${FINAL_COUT}
145
146 #========================================