]> git.lyx.org Git - lyx.git/blob - forms/fdfix.sh
fix one bug
[lyx.git] / forms / fdfix.sh
1 #! /bin/sh
2
3 if [ "$1" = "$2" ]; then
4     echo "Input and Output file can not be the same."
5     exit 1
6 fi
7
8 if [ -f $2 ]; then
9         echo "Output file already exists, overwrite?"
10         read
11         if [ "$REPLY" != "y" ]; then
12             exit 0
13         fi
14 fi
15
16 if [ ! -f $1 ]; then
17     echo "Input file does not exist, can not continue"
18     exit 1
19 fi
20
21 # If there is a patch for the outputfile patch the input file with it.
22 if [ -f "$2.patch" ]; then
23     echo "Patching $1 with $2.patch"
24     patch -s $1 < "$2.patch"
25 fi
26
27 echo "// File modified by fdfix.sh for use by lyx (with xforms > 0.88) and gettext" > $2
28 echo "#include <config.h>" >> $2
29 echo "#include \"lyx_gui_misc.h\"" >> $2
30 echo "#include \"gettext.h\"" >> $2
31 echo >> $2
32
33 # The commands to sed does this:
34 #
35 # -e 's/#include "forms\.h"/#include FORMS_H_LOCATION/'
36 #
37 #  Replace "forms.h" by FORMS_H_LOCATION in #include directives. This
38 #  macro is defined in config.h and is either <forms.h> or
39 #  <X11/forms.h>. 
40 #
41 # -e '/fl_/ s/".[^|]*"/_(&)/'
42 #  
43 #  For all lines containing "fl_" and a string _not_ containging |,
44 #  replace the string with _(string)
45 #
46 # -e '/shortcut/ s/".*[|].*"/scex(_(&))/'
47 #
48 #  For all lines containing "shortcut" and a string containing |, replace
49 #  the string with scex(_(string))
50 #
51 # -e '/fl_add/ s/".*[|].*"/idex(_(&))/'
52 #  For all lines containing "fl_add" and a string containing |, replace
53 #  the string with idex(_(string))
54 #
55 # -e '/fl_add/ s/idex("\(.*\)").*$/&fl_set_button_shortcut(obj,"\1",1);/'
56 # For all lines containing "fl_add" and a string containing |, add the
57 # shortcut command after the end of this line
58 #
59 # -e 's/\(\(FD_[^ ]*\) \*fdui.*\)sizeof(\*fdui)/\1sizeof(\2)/'
60 #
61 #  Some picky/broken compilers (eg AIX's xlC) don't like evaluating  
62 #  sizeof(*fdui) before fdui has been given a value and output a warning. 
63 #  This will not be needed anymore as soon as fdesign is fixed (already 
64 #  reported to its authors).
65 #
66 # -e 's/,\([^ ]\)/, \1/g' \
67 # -e 's/\("[^"][^"]*,\) \("\)/\1\2/g'
68 #
69 # Someone got busy and put spaces in after commas but didn't allow for the
70 # autogeneration of the files so their pretty formatting got lost. Not anymore.
71 # The second rule cleans up one special case where a comma appears at the end
72 # of a string while ensuring "...", "..." isn't affected. Update: this seems
73 # to have not been fixed in fdesign 0.56 (xforms 0.89), we should probably
74 # report it once more. (Lgb)
75 #
76 # -e 's/stdlib.h/cstdlib/'
77 #
78 # Include the right C header.  Another one of those changes made by someone
79 # who forgot that these files are regenerated.
80 #
81 # -e '/fl_.*"[^"]*%.*"/i\
82 #   //xgettext:no-c-format'
83 #
84 # Something else someone got busy adding only to have them removed by the
85 # autogeneration.  Maybe someday I won't have to clean up after everyone else
86 # and will be able to spend my time working on what I want to work on.
87 #
88 # -e 's/NULL/0/'
89 #
90 # Hopefully the last thing that I'll ever have to merge in because in future
91 # everyone will do their own merging when they decide they want to modify a
92 # generated file.
93 #
94 cat $1 | sed \
95 -e 's/#include "forms\.h"/#include FORMS_H_LOCATION/' \
96 -e '/fl_/ s/".[^|]*"/_(&)/' \
97 -e '/shortcut/ s/".*[|].*"/scex(_(&))/' \
98 -e '/fl_add/ s/".*[|].*"/idex(_(&))/' \
99 -e '/fl_add/ s/idex(\(.*\)").*$/&fl_set_button_shortcut(obj,scex(\1")),1);/' \
100 -e 's/\(\(FD_[^ ]*\) \*fdui.*\)sizeof(\*fdui)/\1sizeof(\2)/' \
101 -e 's/,\([^ ]\)/, \1/g' \
102 -e 's/\("[^"][^"]*,\) \("\)/\1\2/g' \
103 -e '/fl_.*"[^"]*%.*"/i\
104   // xgettext:no-c-format' \
105 -e 's/NULL/0/' \
106 -e 's/stdlib.h/cstdlib/' >> $2