]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/forms/fdfix.sh
the 50% overclock Preferences dialog patch
[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.88) 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 "/#include \"form_.*\"/a\\
45 #  #include \"$classname.h\" "
46 #
47 #   For all lines containing "#include "form_*"", append a line
48 #   containing the header file of the parent class
49 #
50 # -e '/fl_/ s/".[^|]*"/_(&)/'
51 #  
52 #  For all lines containing "fl_" and a string _not_ containing |,
53 #  replace the string with _(string)
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 #
62 #  For all lines containing "fl_add" and a string containing |, replace
63 #  the string with idex(_(string))
64 #
65 # -e '/fl_add/ s/idex("\(.*\)").*$/&\
66 #     fl_set_button_shortcut(obj,"\1",1);/'
67 #
68 # For all lines containing "fl_add" and a string containing |, add the
69 # shortcut command after the end of this line
70 #
71 # -e 's/\(\(FD_[^ ]*\) \*fdui =\).*sizeof(\*fdui))/\1 new \2/'
72 #
73 # We use new/delete not malloc/free so change to suit.
74 #
75 # -e "s/\(FD_f\([^ _]*\)_\([^ ]*\)\) \*create_form_form[^ ]*/\1 * $classname::build_\3()/"
76 #
77 # Fixup the name of the create_form... function to have a signature matching
78 # that of the method it will become.
79 #
80 # -e 's/\(fdui->form[^ ]*\)\(.*bgn_form.*\)/\1\2\
81 #     \1->u_vdata = this;/' \
82 #
83 # We need to store a pointer to the dialog in u_vdata so that the callbacks
84 # will work.
85 #
86 # -e 's/,\([^ ]\)/, \1/g'
87 #
88 # Someone got busy and put spaces in after commas but didn't allow for the
89 # autogeneration of the files so their pretty formatting got lost. Not anymore.
90 #
91
92 classname=`basename $1 .c | cut -c6-`
93 firstchar=`echo $classname | cut -c1 | tr a-z A-Z`
94 rest=`echo $classname | cut -c2-`
95 classname=Form$firstchar$rest
96 export classname
97
98 cat $1 | sed \
99 -e 's/#include \"forms\.h\"/#include FORMS_H_LOCATION/' \
100 -e "/#include \"form_.*\"/a\\
101 #include \"$classname.h\" " \
102 -e '/fl_/ s/".[^|]*"/_(&)/' \
103 -e '/shortcut/ s/".*[|].*"/scex(_(&))/' \
104 -e '/fl_add/ s/".*[|].*"/idex(_(&))/' \
105 -e '/fl_add/ s/idex(\(.*\)").*$/&\
106     fl_set_button_shortcut(obj,scex(\1")),1);/' \
107 -e 's/\(\(FD_[^ ]*\) \*fdui =\).*sizeof(\*fdui))/\1 new \2/' \
108 -e "s/\(FD_f\([^ _]*\)_\([^ ]*\)\) \*create_form_form[^ ]*/\1 * $classname::build_\3()/" \
109 -e 's/\(fdui->form[^ ]*\)\(.*bgn_form.*\)/\1\2\
110   \1->u_vdata = this;/' \
111 -e 's/,\([^ ]\)/, \1/g' >> $2