]> git.lyx.org Git - features.git/blob - src/frontends/xforms/forms/fdfixh.sed
e6c6f23fa8e23a50e545e862b70503bb0de73745
[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 # Pretty formatting; 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 # #include "fdesign_base.h" and append the contents of file "extern.tmp".
33 # This latter is a sorted, unique list of any function declarations.
34 /#define FD/{
35 a\
36 \
37 #include "fdesign_base.h"\
38
39 r extern.tmp
40 }
41
42
43 # Rewrite FD_form_xxx as FD_xxx.
44 # This is done both for the structs and for the #define bounding the header.
45 s/\(.*\) FD_form_\(.*\)/\1 FD_\2/
46
47
48 # Rename the function create_form_form_xxx(void) as build_xxx(void *).
49 s/extern \(.*\) create_form_form_\(.*\)[(]void[)]/\1 build_\2(void *)/
50
51
52 # Manipulate the structs:
53 #
54 # Rewrite                       as
55 # typedef struct {              struct FD_xxx : public FD_base {
56 #       FL_FORM *form_xxx;              FL_OBJECT * some_obj;
57 #       void *vdata;                    ...
58 #       char *cdata;            };      
59 #       long  ldata;
60 #       FL_OBJECT *some_obj;
61 #       ...
62 # } FD_xxx;
63 #
64 # This is detailed more closely below 
65
66 # We retain only those lines in the struct that start " FL_OBJECT *",
67 # placing them in the hold space until the end of the struct is reached
68 # and we can ascertain the struct's name.
69
70 # All other lines are deleted:
71 /^typedef struct/d
72 /^      /{; /FL_OBJECT/!d; }
73
74
75 # For all lines starting with FL_OBJECT...
76 /^      FL_OBJECT/{
77
78 # 1. Perform a little pretty formatting.
79 s/\(FL_OBJECT \*\)/\1 /
80
81 # 2. Append to the hold space and delete from the pattern space.
82 H; d
83 }
84
85
86 # The struct is ended by "} FD_xxx;", so now's the time to paste back the
87 # contents of the hold space.
88 /^} FD_.*;/{
89
90 # 1. Rewrite "} FD_xxx;" as   "\nstruct FD_xxx : public FD_base {".
91 s/} \(.*\);/\
92 struct \1 : public FD_base {/
93
94 # 2. The hold space contains the FL_OBJECT lines, preceded by a new line.
95 #    To get rid of this new line, we exchange the contents of the hold and
96 #    pattern spaces, remove the new line and then exchange back.
97 x; s/^\n//; x
98
99 # 3. Paste the contents of the hold space beneath the "struct FD_xxx" line.
100 #    and empty the hold space
101 G; h; s/.*//; x
102
103 # 4. Close the struct and append an empty line.
104 a\
105 };\
106
107 }