]> git.lyx.org Git - features.git/blob - src/frontends/xforms/forms/fdfixc.sed
xforms clean-up, described in detail in my mail of 31 May. See
[features.git] / src / frontends / xforms / forms / fdfixc.sed
1 # \file fdfixc.sed
2 # Copyright 2002 the LyX Team
3 # Read the file COPYING
4 #
5 # \author Angus Leeming, leeming@lyx.org and others
6 #
7 # Use so:
8 # sed -f fdfixc.sed < somefile.c > fixedfile.C
9 #
10 # It contains the instructions that sed requires to manipulate
11 # the .c files produced by fdesign into a form usable by LyX
12
13 # Delete the fdesign comment
14 /generated with fdesign/d
15
16 # Rename struct FD_form_xxx as FD_xxx
17 s/FD_form_\(.*\)/FD_\1/
18
19 # In the struct declaration, we have renamed
20 #       FL_FORM * form_xxx;
21 # as
22 #       FL_FORM * form;
23 # so we must do so here too.
24 #
25 # 1. Rewrite "fdui->form_xxx->fdui = ..." as "fdui->form->fdui = ..."
26 s/fdui->form_\([^ ]*\)->fdui =/fdui->form->fdui =/
27
28 # 2. Rewrite "fdui->form_xxx = ..." as "fdui->form = ..."
29 s/fdui->form_\([^ ]*\) =/fdui->form =/
30
31 # 3. Rewrite "fdui->form_xxx->..." as "fdui->form->..."
32 s/fdui->form_\([^ ]*\)->/fdui->form->/
33
34 # Replace "forms.h" by FORMS_H_LOCATION in the #include directives
35 s/#include \"forms\.h\"/#include FORMS_H_LOCATION/
36
37 # Create the destructor.
38 # When the wrappers are here, delete from here
39 /\(.*\) *create_form_form/{
40 h
41 s/\(.*\) \*create_form_form[^ ]*/\1::~\1()/p
42 /\(.*\)::~\(.*\)()/{
43 i\
44 {\
45   if ( form->visible ) fl_hide_form( form );\
46   fl_free_form( form );\
47 }\
48
49 }
50 x
51 }
52 # When the wrappers are here, delete to here
53
54 # Rename the function create_form_form_xxx(void) as build_xxx()
55 s/\(.*\) \*create_form_form_\(.*\)\([(]void[)]\)/\1 * build_\2(void * parent)/
56
57 # We use new/delete not malloc/free so change to suit
58 s/\(\(FD_[^ ]*\) \*fdui =\).*sizeof(\*fdui))/\1 new \2/
59
60 # For all lines containing "bmtable",
61 # replace "fl_add_button" with "fl_add_bmtable"
62 /bmtable/ s/fl_add_button/fl_add_bmtable/
63
64 # For all lines containing "fl_" and a string _not_ containing |,
65 # replace the string with _(string)
66 /fl_/ s/".[^|]*"/_(&)/
67
68 #  For all lines containing "_shortcut" and a string containing |, 
69 #  replace the string with scex(_(string))
70 /_shortcut/ s/".*[|].*"/scex(_(&))/
71
72 # gettext will get confused if the string contains a "%" unless the line is
73 # preceeded immediately by // xgettext:no-c-format
74 /_(".*[%].*")/i\
75   // xgettext:no-c-format
76
77 # For all lines containing "fl_add" and a string containing |
78 # do several things.
79 # Eg
80 #   fdui->counter_zoom = obj = fl_add_counter(FL_NORMAL_COUNTER,1,2,3,4,"Zoom %|#Z");
81 #
82 # becomes
83 #   fdui->counter_zoom = obj;
84 #   {
85 #     // xgettext:no-c-format
86 #     char const * const dummy = _("Zoom %|#Z");
87 #     fdui->counter_zoom = obj = fl_add_counter(FL_NORMAL_COUNTER,1,2,3,4,idex(dummy));
88 #     fl_set_button_shortcut(obj,scex(dummy),1);
89 #   }
90
91 /fl_add/{
92 /".*[|].*"/{
93
94   s/fdui\(.*\)"\(.*\)".*/  {\
95       char const * const dummy = _("\2");\
96       fdui\1idex(dummy));\
97       fl_set_button_shortcut(obj,scex(dummy),1);\
98     }/
99
100   /_(".*[%].*");/ s/\(.*\)\(char const [*]\)/\1\/\/ xgettext:no-c-format\
101       \2/
102 }
103 }
104
105 # We need to store a pointer to the dialog in u_vdata so that the
106 # callbacks will work.
107 s/\(fdui->form\)\(.*bgn_form.*\)/\1\2\
108   \1->u_vdata = parent;/
109
110 # Someone got busy and put spaces in after commas but didn't allow for the
111 # autogeneration of the files so their pretty formatting got lost. Not anymore.
112 #
113 s/,\([^ ]\)/, \1/g
114
115 # Clean up one special case where a comma appears at the end of a string
116 # while ensuring "...", "..." isn't affected.
117 #
118 s/\("[^"]+,\) \("\)/\1\2/g
119