]> git.lyx.org Git - features.git/blob - src/frontends/xforms/forms/fdfixh.sed
Small clean-up of the sed scripts.
[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 # Strip multiple blank lines, leaving only one
16 /^$/{
17 N
18 /^\n$/D
19 }
20
21 # Rewrite FD_form_xxx as FD_xxx
22 # This is done both for the structs and for the #define bounding the header
23 s/\(.*\) FD_form_\(.*\)/\1 FD_\2/
24
25 # Forward declare FL_FORM and FL_OBJECT
26 /#define FD/a\
27 \
28 #include "forms_fwd.h"
29
30 # Delete the fdesign comments
31 /Callbacks, globals/d
32 /generated with fdesign/d
33 /Forms and Objects/d
34
35 # Replace lines such as "extern void func(args);"
36 # with "extern "C" void func(args);"
37 # Note that these should not occur because we should be using signals. See the
38 # README file for further information.
39 s/\(extern \)\(void \)\(.*\)/\1 "C" \2\3/
40
41 # Rename the function create_form_form_xxx(void) as build_xxx(void * parent)
42 s/extern \(.*\) create_form_form_\(.*\)\([(]void[)]\)/\1 build_\2(void *)/
43
44 # Manipulate the structs
45 #
46 # Rewrite                       as
47 # typedef struct {              struct FD_xxx {
48 #       FL_FORM *form_xxx;              ~FD_xxx();
49 #       void *vdata;                    FL_FORM   * form;
50 #       char *cdata;                    FL_OBJECT * some_obj;
51 #       long  ldata;                    ...
52 #       FL_OBJECT *some_obj;    };
53 #       ...
54 # } FD_xxx;
55 #
56 # This is detailed more closely below 
57
58 # Delete lines containing:
59 /typedef struct/d
60 /vdata/d
61 /cdata/d
62 /ldata/d
63
64 # Place all lines containing FL_FORM and FL_OBJECT in the hold space, deleting
65 # them from the pattern space.
66
67 # For all lines containing FL_FORM...
68 /FL_FORM/{
69
70 # Rewrite "FL_FORM *form_xxx;" as "FL_FORM   * form;
71 # Note that the spaces before FL_FORM are replaced with a <tab>
72 s/\(.*\)FL_FORM \(.*\)/ FL_FORM   * form;/
73
74 # We know that FL_FORM comes before any FL_OBJECT, so can initialise
75 # the hold space with it.
76 h
77 d
78
79 }
80
81 # For all lines containing FL_OBJECT and not containing extern...
82 /FL_OBJECT/{
83 /extern/!{
84
85 # perform a little pretty formatting
86 s/\(.*\)FL_OBJECT \([*]\)\(.*\)/        FL_OBJECT * \3/
87
88 # append to the hold space
89 H
90 d
91
92 }
93 }
94
95 # The struct is ended by "} FD_xxx;", so now's the time to paste back the
96 # contents of the hold space.
97 /} FD_/{
98 # 1. Insert an empty line.
99 i\
100
101 # 2. Rewrite "} FD_xxx;" as   "struct FD_xxx {" and append a d-tor.
102 s/} \(.*\);/struct \1 {\
103         ~\1();/
104
105 # 3. Paste the contents of the hold space beneath it
106 G
107
108 # 4. Close the struct
109 a\
110 };
111 }