]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/forms/fdfix.sh
Change the semantics of 'none' and 'auto' viewers/editors: 'none' means now
[lyx.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 test $# -eq 1 || {
19         echo "Expected a file name!"
20         exit 1
21 }
22
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
26 # recognise ;-)
27
28 cat - > $1 <<EOF
29 // File generated by fdesign from ${FDFILE}
30 // and modified by fdfix.sh for use by LyX.
31
32 // WARNING! All changes made to this file will be lost!
33
34 // This file is part of LyX, the document processor.
35 // Licence details can be found in the file COPYING.
36
37 EOF
38 }
39
40 #===============
41 # Initial checks
42 if [ ! -f $1 ]; then
43         echo "Input file does not exist. Cannot continue"
44         exit 1
45 fi
46
47 DIRNAME=`dirname $1`
48 BASENAME=`basename $1 .fd`
49
50 FDFIXH_SED=`dirname $0`/fdfixh.sed
51 FDFIXC_SED=`dirname $0`/fdfixc.sed
52 TMP_STR_SED=`dirname $0`/tmp_str.sed
53
54 if [ $1 = ${BASENAME} ]; then
55         echo "Input file is not a .fd file. Cannot continue"
56         exit 1
57 fi
58
59 #===================================
60 # Create the initial .c and .h files
61 FDESIGN=fdesign
62 FDFILE=${BASENAME}.fd
63
64 (cd ${DIRNAME} && ${FDESIGN} -convert ${FDFILE}) ||
65 {
66         echo "\"${FDESIGN} -convert ${FDFILE}}\" failed. Please investigate."
67         exit 1
68 }
69
70 #==================================
71 # Modify the .h file for use by LyX
72 HIN=${DIRNAME}/${BASENAME}.h
73 HPATCH=${DIRNAME}/${BASENAME}.h.patch
74 HOUT=${BASENAME}.hpp
75
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
79 # output by fdesign
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}
84
85 if [ -s ${EXTERN_FUNCS} ]; then
86         TMP=tmp.$$
87         sort -u ${EXTERN_FUNCS} > ${TMP}
88         echo "extern \"C\" {" > ${EXTERN_FUNCS}
89         cat ${TMP} >> ${EXTERN_FUNCS}
90         echo "}" >> ${EXTERN_FUNCS}
91         rm -f ${TMP}
92 fi
93
94 # First ensure that the sed script knows where to find ${EXTERN_FUNCS}
95 FDFIXH=fdfixh.$$
96 sed "s/EXTERN_FUNCS/${EXTERN_FUNCS}/" ${FDFIXH_SED} > ${FDFIXH}
97
98 INTRO_MESSAGE ${HOUT}
99
100 sed -f ${FDFIXH} < ${HIN} >> ${HOUT}
101
102 # Don't forget to clean up the temporary files.
103 rm -f ${EXTERN_FUNCS} ${FDFIXH}
104
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}
109 fi
110
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.
116 rm -f ${HIN}
117 MOVE_H_FILE=1
118 if [ -r ${BASENAME}.h ]; then
119         cmp -s ${HOUT} ${BASENAME}.h && MOVE_H_FILE=0
120 fi
121
122 if [ ${MOVE_H_FILE} -eq 1 ]; then
123         mv ${HOUT} ${BASENAME}.h
124 else
125         rm -f ${HOUT}
126 fi
127
128 #==================================
129 # Create the .C file for use by LyX
130 CIN=${DIRNAME}/${BASENAME}.c
131 CPATCH=${DIRNAME}/${BASENAME}.C.patch
132 COUT=${BASENAME}.cpp
133 FINAL_COUT=${BASENAME}.C
134
135 # We use a two pass algorithm to generate elegant C++ code whilst
136 # keeping the sed clean also.
137
138 # Pass 1. The bulk of the clean-up
139 TMP=tmp.$$
140 INTRO_MESSAGE ${TMP}
141
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}
151
152 sed -f ${FDFIXC_SED} < ${CIN} >> ${TMP}
153
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}
157 rm -f ${TMP}
158
159 if [ -f "${CPATCH}" ] ; then
160         echo "Patching ${COUT} with ${CPATCH}"
161         patch -s ${COUT} < ${CPATCH}
162 fi
163
164 # Clean up, to leave the finished .C file
165 rm -f ${CIN}
166 mv ${COUT} ${FINAL_COUT}
167
168 #========================================