]> git.lyx.org Git - features.git/blob - src/frontends/xforms/forms/fdfixh.sed
I reckon that the generated .h files and the scripts that modify them
[features.git] / src / frontends / xforms / forms / fdfixh.sed
1 # file fdfixh.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 fdfixh.sed < somefile.h > fixedfile.h
11 #
12 # It contains the instructions that sed requires to manipulate
13 # the .h files produced by fdesign into a form usable by LyX
14
15 # Remove trailing whitespace.
16 s/[     ]*$//
17
18
19 # Delete blank lines, "extern void" function declarations and fdesign comments.
20 /^$/d
21 /^extern void/d
22 /Forms and Objects/d
23 /Callbacks, globals/d
24 /generated with fdesign/d
25
26
27 # Pretty formatting; add an empty line before "#endif"
28 /#endif/i\
29
30
31 # Immediately after line "#define FD_xxx_h_" that starts off the header file,
32 # forward declare FL_FORM and FL_OBJECT and append the contents of file
33 # "extern.tmp". This latter is a sorted, unique list of any function
34 # declarations.
35 /#define FD/{
36 a\
37 \
38 #include "forms_fwd.h"\
39
40 r extern.tmp
41 }
42
43
44 # Rewrite FD_form_xxx as FD_xxx.
45 # This is done both for the structs and for the #define bounding the header.
46 s/\(.*\) FD_form_\(.*\)/\1 FD_\2/
47
48
49 # Rename the function create_form_form_xxx(void) as build_xxx(void *).
50 s/extern \(.*\) create_form_form_\(.*\)[(]void[)]/\1 build_\2(void *)/
51
52
53 # Manipulate the structs:
54 #
55 # Rewrite                       as
56 # typedef struct {              struct FD_xxx {
57 #       FL_FORM *form_xxx;              ~FD_xxx();
58 #       void *vdata;                    FL_FORM   * form;
59 #       char *cdata;                    FL_OBJECT * some_obj;
60 #       long  ldata;                    ...
61 #       FL_OBJECT *some_obj;    };
62 #       ...
63 # } FD_xxx;
64 #
65 # This is detailed more closely below 
66
67 # Delete lines containing:
68 /typedef struct/d
69 /vdata/d
70 /cdata/d
71 /ldata/d
72
73 # Place all lines containing FL_FORM and FL_OBJECT in the hold space, deleting
74 # them from the pattern space.
75
76 # For all lines starting with FL_FORM...
77 /^      FL_FORM/{
78
79 # 1. Rewrite "FL_FORM *form_xxx;" as "FL_FORM   * form;
80 s/FL_FORM[ ]*\*form.*/FL_FORM   * form;/
81
82 # 2. We know that FL_FORM comes before any FL_OBJECT, so can initialise
83 # the hold space with it. Delete from the pattern space.
84 h
85 d
86 }
87
88 # For all lines starting with FL_OBJECT...
89 /^      FL_OBJECT/{
90
91 # 1. Perform a little pretty formatting.
92 s/FL_OBJECT \*\(.*\)/FL_OBJECT * \1/
93
94 # 2. Append to the hold space and delete from the pattern space.
95 H
96 d
97 }
98
99 # The struct is ended by "} FD_xxx;", so now's the time to paste back the
100 # contents of the hold space.
101 /} FD_/{
102 # 1. Insert an empty line.
103 i\
104
105 # 2. Rewrite "} FD_xxx;" as   "struct FD_xxx {" and append a d-tor.
106 s/} \(.*\);/struct \1 {\
107         ~\1();/
108
109 # 3. Paste the contents of the hold space beneath it.
110 G
111
112 # 4. Close the struct and append an empty line.
113 a\
114 };\
115
116 }