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