]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/forms/fdfix.sh
Patch fdfix from Angus, using only the new tabular-layout, some fixes!
[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 if [ "$1" = "$2" ]; then
7     echo "Input and Output file can not be the same."
8     exit 1
9 fi
10
11 if [ -f $2 ]; then
12         echo "Output file already exists, overwrite?"
13         read
14         if [ "$REPLY" != "y" ]; then
15             exit 0
16         fi
17 fi
18
19 if [ ! -f $1 ]; then
20     echo "Input file does not exist, can not continue"
21     exit 1
22 fi
23
24 # If there is a patch for the outputfile patch the input file with it.
25 if [ -f "$2.patch" ]; then
26     echo "Patching $1 with $2.patch"
27     patch -s $1 < "$2.patch"
28 fi
29
30 echo "// File modified by fdfix.sh for use by lyx (with xforms >= 0.86) and gettext" > $2
31 echo "#include <config.h>" >> $2
32 echo "#include \"lyx_gui_misc.h\"" >> $2
33 echo "#include \"gettext.h\"" >> $2
34 echo >> $2
35
36 # The commands to sed does this:
37 #
38 # -e 's/#include "forms\.h"/#include FORMS_H_LOCATION/'
39 #
40 #  Replace "forms.h" by FORMS_H_LOCATION in #include directives. This
41 #  macro is defined in config.h and is either <forms.h> or
42 #  <X11/forms.h>. 
43 #
44 # -e '/fl_/ s/".[^|]*"/_(&)/'
45 #  
46 #  For all lines containing "fl_" and a string _not_ containging |,
47 #  replace the string with _(string)
48 #
49 #  -e "/#include \"form_.*\"/a\\
50 #  #include \"$classname.h\" "
51 #
52 #   For all lines containing "#include "form_*"", append a line
53 #   containing the header file of the parent class
54 #
55 # -e '/shortcut/ s/".*[|].*"/scex(_(&))/'
56 #
57 #  For all lines containing "shortcut" and a string containing |, replace
58 #  the string with scex(_(string))
59 #
60 # -e '/fl_add/ s/".*[|].*"/idex(_(&))/'
61 #  For all lines containing "fl_add" and a string containing |, replace
62 #  the string with idex(_(string))
63 #
64 # -e '/fl_add/ s/idex("\(.*\)").*$/&fl_set_button_shortcut(obj,"\1",1);/'
65 # For all lines containing "fl_add" and a string containing |, add the
66 # shortcut command after the end of this line
67 #
68 # -e 's/,\([^ ]\)/, \1/g'
69 #
70 # Someone got busy and put spaces in after commas but didn't allow for the
71 # autogeneration of the files so their pretty formatting got lost. Not anymore.
72 #
73 # -e 's/\(\(FD_[^ ]*\) \*fdui =\).*sizeof(\*fdui))/\1 dialog_ = new \2/'
74 #
75 # We use new/delete not malloc/free so change to suit.  Also the local
76 # variable for our dialog is called dialog_ so do that fix also.
77 #
78 #-e 's/\(FD_f\([^ ]*\)_\([^ ]*\)\) \*create[^ ]*/void F\2\3::build()/'
79 #
80 # Fixup the name of the create_form... function to have a signature almost
81 # matching that of the method it will become.  You just need to capitalize
82 # the forms name.
83 #
84 #   -e 's/\(fdui->form[^ ]*\)\(.*bgn_form.*\)/\1\2\
85 #     \1->u_vdata = this;/' \
86 #
87 # We need to store a pointer to the dialog in u_vdata so that the callbacks
88 # will work.
89 #
90
91 classname=`basename $1 .c | cut -c6-`
92 firstchar=`echo $classname | cut -c1 | tr a-z A-Z`
93 rest=`echo $classname | cut -c2-`
94 classname=Form$firstchar$rest
95 export classname
96
97 cat $1 | sed \
98 -e 's/#include \"forms\.h\"/#include FORMS_H_LOCATION/' \
99 -e "/#include \"form_.*\"/a\\
100 #include \"$classname.h\" " \
101 -e '/fl_/ s/".[^|]*"/_(&)/' \
102 -e '/shortcut/ s/".*[|].*"/scex(_(&))/' \
103 -e '/fl_add/ s/".*[|].*"/idex(_(&))/' \
104 -e '/fl_add/ s/idex(\(.*\)").*$/&fl_set_button_shortcut(obj,scex(\1")),1);/' \
105 -e 's/\(\(FD_[^ ]*\) \*fdui =\).*sizeof(\*fdui))/\1 new \2/' \
106 -e "s/\(FD_f\([^ _]*\)_\([^ ]*\)\) \*create_form_form[^ ]*/\1 * $classname::build_\3()/" \
107 -e 's/\(fdui->form[^ ]*\)\(.*bgn_form.*\)/\1\2\
108   \1->u_vdata = this;/' \
109 -e 's/,\([^ ]\)/, \1/g' >> $2