]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/forms/fdfix.sh
apply the patch from Angus
[lyx.git] / src / frontends / xforms / forms / fdfix.sh
1 #! /bin/sh
2 #
3 # NOTE: This is NOT the same fdfix.sh as in ${top_srcdir}/forms
4 #       It is a modified version to suit use for gui-indep.
5 #
6
7 if [ ! -f $1 ]; then
8     echo "Input file does not exist. Cannot continue"
9     exit 1
10 fi
11
12 FDESIGN=fdesign
13
14 # names of the files generated by fdesign and by running the sed scripts
15 BASE=`basename $1 .fd`
16
17 if [ $1 = $BASE ]; then
18     echo "Input file is not a .fd file. Cannot continue"
19     exit 1
20 fi
21
22 CIN=$BASE.c
23 COUT=$BASE.C
24 HIN=$BASE.h
25 HOUT=$BASE.H
26
27 # Ascertain the class name from the name of the file
28 # eg form_my_new_dialog -> FormMyNewDialog
29 CLASSNAME=""
30 SECTION="start"
31 i=1
32 while :
33 do
34     SECTION=`echo $BASE | cut -d_ -f$i`
35     i=`expr $i + 1 `
36
37     if [ $SECTION ]
38     then
39         FIRST=`echo $SECTION | cut -c1 | tr a-z A-Z`
40         SECOND=`echo $SECTION | cut -c2-`
41         CLASSNAME=$CLASSNAME$FIRST$SECOND
42     else
43         break
44     fi
45 done
46
47 # Create .c and .h files
48 $FDESIGN -convert $1
49 FDFIXH=fdfixh.sed
50 FDFIXC=fdfixc.sed
51 FDFIXC_MOD=fdfixc_modified.sed
52
53 # Modify .h file for use by LyX
54 echo "// File modified by fdfix.sh for use by lyx (with xforms >= 0.88) and gettext" > $HOUT
55 sed -f $FDFIXH < $HIN >> $HOUT
56
57 # Patch the .h file if a patch exists
58 if [ -f "$HOUT.patch" ] ; then
59     echo "Patching $HOUT with $HOUT.patch"
60     patch -s $HOUT < $HOUT.patch
61 fi
62
63 # Modify the .c file sed-script
64 # (Quicker to modify the sed script than the .c file!)
65 sed -e "s/CLASSNAME/$CLASSNAME/" < $FDFIXC > $FDFIXC_MOD
66
67 # Modify .c file for use by LyX
68 echo "// File modified by fdfix.sh for use by lyx (with xforms >= 0.88) and gettext" > $COUT
69 echo "#include <config.h>" >> $COUT
70 echo "#include \"lyx_gui_misc.h\"" >> $COUT
71 echo "#include \"gettext.h\"" >> $COUT
72 echo >> $COUT
73
74 sed -f $FDFIXC_MOD < $CIN >> $COUT
75
76 # Patch the .C file if a patch exists
77 if [ -f "$COUT.patch" ] ; then
78     echo "Patching $COUT with $COUT.patch"
79     patch -s $COUT < $COUT.patch
80 fi
81
82 # Clean up, to leave .C and .h files
83 rm -f $CIN $HIN $FDFIXC_MOD
84 mv $HOUT $HIN