# It contains the instructions that sed requires to manipulate
# the .c files produced by fdesign into a form usable by LyX
-# Delete the fdesign comment
+# Pretty formatting; remove trailing whitespace.
+s/[ ]*$//
+
+
+# Delete blank lines and fdesign comments.
+/^$/d
/generated with fdesign/d
+/^\/\*-----/d
+
+
+# Replace "forms.h" by FORMS_H_LOCATION in the #include directives
+s/#include \"forms\.h\"/#include FORMS_H_LOCATION/
+
+
+# Pretty formatting; replace all leading whitespace with a tab
+/^[ ]/s/^[ ]*/ /
-# Rename struct FD_form_xxx as FD_xxx
+
+# Rename struct "FD_form_xxx" as "FD_xxx"
s/FD_form_\(.*\)/FD_\1/
-# In the struct declaration, we have renamed
-# FL_FORM * form_xxx;
-# as
-# FL_FORM * form;
-# so we must do so here too.
-#
+
+# Rename the function create_form_form_xxx(void) as build_xxx()
+s/\(.*\) \*create_form_form_\(.*\)\([(]void[)]\)/\
+\
+\1 * build_\2(void * parent)/
+
+
+# Pretty formatting
+s/FL_OBJECT \*obj;/FL_OBJECT * obj;\
+/
+
+# Insert a line before each new FL_OBJECT
+/obj = /i\
+
+# Ditto for fl_bgn
+/fl_bgn/i\
+
+# Ditto for fl_end
+/fl_end/i\
+
+
# Rewrite "fdui->form_xxx" as "fdui->form"
# xxx is followed by ' ', '->' or ')', so use these to flag when xxx ends.
/fdui->form/s/\(fdui->form\)_[^ )-]*/\1/
-# Replace "forms.h" by FORMS_H_LOCATION in the #include directives
-s/#include \"forms\.h\"/#include FORMS_H_LOCATION/
-# Create the destructor.
-# When the wrappers are here, delete from here
-/\(.*\) *create_form_form/{
-h
-s/\(.*\) \*create_form_form[^ ]*/\1::~\1()/p
-/\(.*\)::~\(.*\)()/{
-i\
-{\
- if ( form->visible ) fl_hide_form( form );\
- fl_free_form( form );\
-}\
-
-}
-x
-}
-# When the wrappers are here, delete to here
+# We use new/delete not malloc/free so change to suit.
+s/\(\(FD_[^ ]*\) \*fdui =\).*sizeof(\*fdui))/\1 new \2/
-# Rename the function create_form_form_xxx(void) as build_xxx()
-s/\(.*\) \*create_form_form_\(.*\)\([(]void[)]\)/\1 * build_\2(void * parent)/
-# We use new/delete not malloc/free so change to suit
-s/\(\(FD_[^ ]*\) \*fdui =\).*sizeof(\*fdui))/\1 new \2/
+# We need to store a pointer to the dialog in u_vdata so that the
+# callbacks will work.
+s/\( fdui->form\)\(.*bgn_form.*\)/\1\2\
+\1->u_vdata = parent;/
+
# For all lines containing "bmtable",
# replace "fl_add_button" with "fl_add_bmtable"
/bmtable/ s/fl_add_button/fl_add_bmtable/
+
# For all lines containing "fl_" and a string _not_ containing |,
# replace the string with _(string)
/fl_/ s/".[^|]*"/_(&)/
+
# For all lines containing "_shortcut" and a string containing |,
# replace the string with scex(_(string))
/_shortcut/ s/".*[|].*"/scex(_(&))/
-# gettext will get confused if the string contains a "%" unless the line is
-# preceeded immediately by // xgettext:no-c-format
-/_(".*[%].*")/i\
- // xgettext:no-c-format
# For all lines containing "fl_add" and a string containing |
-# do several things.
-# Eg
-# fdui->counter_zoom = obj = fl_add_counter(FL_NORMAL_COUNTER,1,2,3,4,"Zoom %|#Z");
-#
+# change so:
+# fdui->counter_zoom = obj = fl_add_counter(...,"Zoom %|#Z");
# becomes
-# fdui->counter_zoom = obj;
-# {
-# // xgettext:no-c-format
-# char const * const dummy = _("Zoom %|#Z");
-# fdui->counter_zoom = obj = fl_add_counter(FL_NORMAL_COUNTER,1,2,3,4,idex(dummy));
-# fl_set_button_shortcut(obj,scex(dummy),1);
-# }
-
-/fl_add/{
-/".*[|].*"/{
-
- s/fdui\(.*\)"\(.*\)".*/ {\
- char const * const dummy = _("\2");\
- fdui\1idex(dummy));\
- fl_set_button_shortcut(obj,scex(dummy),1);\
- }/
-
- /_(".*[%].*");/ s/\(.*\)\(char const [*]\)/\1\/\/ xgettext:no-c-format\
- \2/
-}
-}
+# c_str = _("Zoom %|#Z");
+# fdui->counter_zoom = obj = fl_add_counter(...,idex(c_str));
+# fl_set_button_shortcut(obj,scex(c_str),1);
+
+/fl_add.*".*[|].*"/s/fdui\(.*\)"\(.*\)".*/c_str = _("\2");\
+ fdui\1idex(c_str));\
+ fl_set_button_shortcut(obj,scex(c_str),1);/
+
+
+# gettext will get confused if the string contains a "%" unless the line is
+# preceeded immediately by "// xgettext:no-c-format"
+/_(".*[%].*")/i\
+ // xgettext:no-c-format
-# We need to store a pointer to the dialog in u_vdata so that the
-# callbacks will work.
-s/\(fdui->form\)\(.*bgn_form.*\)/\1\2\
- \1->u_vdata = parent;/
# Someone got busy and put spaces in after commas but didn't allow for the
# autogeneration of the files so their pretty formatting got lost. Not anymore.
# while ensuring "...", "..." isn't affected.
#
s/\("[^"]+,\) \("\)/\1\2/g
-
# It contains the instructions that sed requires to manipulate
# the .h files produced by fdesign into a form usable by LyX
-# Remove trailing whitespace.
+# Pretty formatting; remove trailing whitespace.
s/[ ]*$//
# Immediately after line "#define FD_xxx_h_" that starts off the header file,
-# forward declare FL_FORM and FL_OBJECT and append the contents of file
-# "extern.tmp". This latter is a sorted, unique list of any function
-# declarations.
+# #include "fdesign_base.h" and append the contents of file "extern.tmp".
+# This latter is a sorted, unique list of any function declarations.
/#define FD/{
a\
\
-#include "forms_fwd.h"\
+#include "fdesign_base.h"\
r extern.tmp
}
# Manipulate the structs:
#
# Rewrite as
-# typedef struct { struct FD_xxx {
-# FL_FORM *form_xxx; ~FD_xxx();
-# void *vdata; FL_FORM * form;
-# char *cdata; FL_OBJECT * some_obj;
-# long ldata; ...
-# FL_OBJECT *some_obj; };
+# typedef struct { struct FD_xxx : public FD_base {
+# FL_FORM *form_xxx; FL_OBJECT * some_obj;
+# void *vdata; ...
+# char *cdata; };
+# long ldata;
+# FL_OBJECT *some_obj;
# ...
# } FD_xxx;
#
# This is detailed more closely below
-# Delete lines containing:
-/typedef struct/d
-/vdata/d
-/cdata/d
-/ldata/d
+# We retain only those lines in the struct that start " FL_OBJECT *",
+# placing them in the hold space until the end of the struct is reached
+# and we can ascertain the struct's name.
-# Place all lines containing FL_FORM and FL_OBJECT in the hold space, deleting
-# them from the pattern space.
+# All other lines are deleted:
+/^typedef struct/d
+/^ FL_FORM/d
+/[vcl]data/d
-# For all lines starting with FL_FORM...
-/^ FL_FORM/{
-
-# 1. Rewrite "FL_FORM *form_xxx;" as "FL_FORM * form;
-s/FL_FORM[ ]*\*form.*/FL_FORM * form;/
-
-# 2. We know that FL_FORM comes before any FL_OBJECT, so can initialise
-# the hold space with it. Delete from the pattern space.
-h
-d
-}
# For all lines starting with FL_OBJECT...
/^ FL_OBJECT/{
# 1. Perform a little pretty formatting.
-s/FL_OBJECT \*\(.*\)/FL_OBJECT * \1/
+s/\(FL_OBJECT \*\)/\1 /
# 2. Append to the hold space and delete from the pattern space.
-H
-d
+H; d
}
+
# The struct is ended by "} FD_xxx;", so now's the time to paste back the
# contents of the hold space.
/} FD_/{
-# 1. Insert an empty line.
-i\
-# 2. Rewrite "} FD_xxx;" as "struct FD_xxx {" and append a d-tor.
-s/} \(.*\);/struct \1 {\
- ~\1();/
+# 1. Rewrite "} FD_xxx;" as "\nstruct FD_xxx : public FD_base {".
+s/} \(.*\);/\
+struct \1 : public FD_base {/
+
+# 2. The hold space contains the FL_OBJECT lines, preceded by a new line.
+# To get rid of this new line, we exchange the contents of the hold and
+# pattern spaces, remove the new line and then exchange back.
+x; s/^\n//; x
-# 3. Paste the contents of the hold space beneath it.
-G
+# 3. Paste the contents of the hold space beneath the "struct FD_xxx" line.
+# and empty the hold space
+G; h; s/.*//; x
# 4. Close the struct and append an empty line.
a\