]> git.lyx.org Git - features.git/commitdiff
Finish the business of strengthening the sed scripts and beautifying
authorAngus Leeming <leeming@lyx.org>
Tue, 26 Nov 2002 19:29:39 +0000 (19:29 +0000)
committerAngus Leeming <leeming@lyx.org>
Tue, 26 Nov 2002 19:29:39 +0000 (19:29 +0000)
the resultant C++ code. Also results in less bloat.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@5723 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/xforms/ChangeLog
src/frontends/xforms/FormBase.h
src/frontends/xforms/Makefile.am
src/frontends/xforms/fdesign_base.C [new file with mode: 0644]
src/frontends/xforms/fdesign_base.h [new file with mode: 0644]
src/frontends/xforms/forms/Makefile.am
src/frontends/xforms/forms/fdfix.sh
src/frontends/xforms/forms/fdfixc.sed
src/frontends/xforms/forms/fdfixh.sed

index 77c3e9f972da84ef512cfc5371db6c20d937c90c..4457579fd75bec9604e3aedf1a1c55b57ca894f8 100644 (file)
@@ -1,3 +1,21 @@
+2002-11-26  Angus Leeming  <leeming@lyx.org>
+
+       * FormBase.h (FormDB::form): Implement in 1 line not 2.
+
+       * fdesign_base.[Ch]: new files. All fdesign-generated structures will
+       derive from FD_base, to minimise code duplication.
+
+       * Makefile.am: add new files.
+
+       * forms/Makefile.am (SRCS): move form_wrap.fd to the end of the list.
+
+       * forms/fdfix.sh: add "c_str" to namespace anon in the generated .C
+       files if required.
+
+       * forms/fdfix[ch].sed: the structs now derive from FD_base, so they
+       don't need d-tors to clean up the form.
+       Beautify the sed to produce beautiful looking C++ code.
+
 2002-11-26  Jean-Marc Lasgouttes  <Jean-Marc.Lasgouttes@inria.fr>
 
        * FileDialog.C (save): actually return the result from
index 9fe1f6eba7ca55d915b4d30cc069c60de741bdfc..9871b5484c177f8b91dfdb30f1262413d26dea9f 100644 (file)
@@ -158,8 +158,7 @@ FormDB<Dialog>::FormDB(string const & t, bool allowResize)
 template <class Dialog>
 FL_FORM * FormDB<Dialog>::form() const
 {
-       if (dialog_.get()) return dialog_->form;
-       return 0;
+       return dialog_.get() ? dialog_->form : 0;
 }
 
 
index 57cbad72be30abc5578c8a73c833ab04668ec57e..4bf9e7a78aeeee7a1e058e3b23469e9906d7bcb0 100644 (file)
@@ -27,6 +27,8 @@ libxforms_la_SOURCES = \
        checkedwidgets.h \
        combox.C \
        combox.h \
+       fdesign_base.C \
+       fdesign_base.h \
        input_validators.C \
        input_validators.h \
        lyx_gui.C \
diff --git a/src/frontends/xforms/fdesign_base.C b/src/frontends/xforms/fdesign_base.C
new file mode 100644 (file)
index 0000000..b84c1f3
--- /dev/null
@@ -0,0 +1,29 @@
+/**
+ * \file fdesign_base.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Angus Leeming
+ *
+ * Full author contact details are available in file CREDITS
+ */
+
+#include <config.h>
+
+#ifdef __GNUG__
+#pragma implementation
+#endif
+
+#include "fdesign_base.h"
+#include FORMS_H_LOCATION
+
+FD_base::~FD_base()
+{
+       if (!form)
+               return;
+
+       if (form->visible)
+               fl_hide_form(form);
+
+       fl_free_form(form);
+}
diff --git a/src/frontends/xforms/fdesign_base.h b/src/frontends/xforms/fdesign_base.h
new file mode 100644 (file)
index 0000000..77751c5
--- /dev/null
@@ -0,0 +1,27 @@
+// -*- C++ -*-
+/**
+ * \file fdesign_base.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Angus Leeming
+ *
+ * Full author contact details are available in file CREDITS
+ */
+
+#ifndef FDESIGN_BASE_H
+#define FDESIGN_BASE_H
+
+#ifdef __GNUG__
+#pragma interface
+#endif
+
+#include "forms_fwd.h"
+
+/// A base class for the fdesign-generated structs
+struct FD_base {
+       virtual ~FD_base();
+       FL_FORM * form;
+};
+
+#endif // FDESIGN_BASE_H
index 1dd0be27fc843590a57e4013350e0ff0e8a8644e..68fac49fdf8cdcf1b94a8122466959401acd7ae4 100644 (file)
@@ -19,7 +19,6 @@ SRCS =  form_aboutlyx.fd \
        form_external.fd \
        form_filedialog.fd \
        form_float.fd \
-       form_wrap.fd \
        form_forks.fd \
        form_graphics.fd \
        form_include.fd \
@@ -44,7 +43,8 @@ SRCS =  form_aboutlyx.fd \
        form_texinfo.fd \
        form_thesaurus.fd \
        form_toc.fd \
-       form_url.fd
+       form_url.fd \
+       form_wrap.fd
 
 libfdesign_la_SOURCES = $(SRCS:.fd=.C) $(SRCS:.fd=.h)
 
index 1c106032009807854c5b0c1e7c6d8319c7497778..a8c7f51c4a118f9b18525a545af54fe85dc1277f 100644 (file)
@@ -121,6 +121,17 @@ FDFIXC=${DIRNAME}/fdfixc.sed
 
 OUTPUT_FILE=${COUT}; INTRO_MESSAGE
 
+# This "c_str" is potentially used many times in many functions
+# so add it to the top of the generated file.
+grep -E 'fl_add.*".*[|].*"' ${CIN} > /dev/null &&
+       cat - >> ${COUT} <<EOF
+namespace {
+char const * c_str;
+} // namespace anon
+
+
+EOF
+
 echo "#include <config.h>" >> ${COUT}
 echo "#include \"forms_gettext.h\"" >> ${COUT}
 echo "#include \"gettext.h\"" >> ${COUT}
index 5777928020635fd2764a0a355230760d4a385ecd..55dc43d258eaaa10ae4e4c0d61c7620cb20fb7b2 100644 (file)
 # 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.
@@ -113,4 +112,3 @@ s/,\([^ ]\)/, \1/g
 # while ensuring "...", "..." isn't affected.
 #
 s/\("[^"]+,\) \("\)/\1\2/g
-
index 93e80dc24d2c9a572d3c6ba4ecc9dd74fef03ded..62c5e2969a8e421f3a61b758dae4db3b25babcbb 100644 (file)
@@ -12,7 +12,7 @@
 # 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/[    ]*$//
 
 
@@ -29,13 +29,12 @@ 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
 }
@@ -53,61 +52,54 @@ s/extern \(.*\) create_form_form_\(.*\)[(]void[)]/\1 build_\2(void *)/
 # 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\