mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-10 20:04:46 +00:00
Finish the business of strengthening the sed scripts and beautifying
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
This commit is contained in:
parent
525a57ac01
commit
1cf60e7a19
@ -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>
|
2002-11-26 Jean-Marc Lasgouttes <Jean-Marc.Lasgouttes@inria.fr>
|
||||||
|
|
||||||
* FileDialog.C (save): actually return the result from
|
* FileDialog.C (save): actually return the result from
|
||||||
|
@ -158,8 +158,7 @@ FormDB<Dialog>::FormDB(string const & t, bool allowResize)
|
|||||||
template <class Dialog>
|
template <class Dialog>
|
||||||
FL_FORM * FormDB<Dialog>::form() const
|
FL_FORM * FormDB<Dialog>::form() const
|
||||||
{
|
{
|
||||||
if (dialog_.get()) return dialog_->form;
|
return dialog_.get() ? dialog_->form : 0;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -27,6 +27,8 @@ libxforms_la_SOURCES = \
|
|||||||
checkedwidgets.h \
|
checkedwidgets.h \
|
||||||
combox.C \
|
combox.C \
|
||||||
combox.h \
|
combox.h \
|
||||||
|
fdesign_base.C \
|
||||||
|
fdesign_base.h \
|
||||||
input_validators.C \
|
input_validators.C \
|
||||||
input_validators.h \
|
input_validators.h \
|
||||||
lyx_gui.C \
|
lyx_gui.C \
|
||||||
|
29
src/frontends/xforms/fdesign_base.C
Normal file
29
src/frontends/xforms/fdesign_base.C
Normal file
@ -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);
|
||||||
|
}
|
27
src/frontends/xforms/fdesign_base.h
Normal file
27
src/frontends/xforms/fdesign_base.h
Normal file
@ -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
|
@ -19,7 +19,6 @@ SRCS = form_aboutlyx.fd \
|
|||||||
form_external.fd \
|
form_external.fd \
|
||||||
form_filedialog.fd \
|
form_filedialog.fd \
|
||||||
form_float.fd \
|
form_float.fd \
|
||||||
form_wrap.fd \
|
|
||||||
form_forks.fd \
|
form_forks.fd \
|
||||||
form_graphics.fd \
|
form_graphics.fd \
|
||||||
form_include.fd \
|
form_include.fd \
|
||||||
@ -44,7 +43,8 @@ SRCS = form_aboutlyx.fd \
|
|||||||
form_texinfo.fd \
|
form_texinfo.fd \
|
||||||
form_thesaurus.fd \
|
form_thesaurus.fd \
|
||||||
form_toc.fd \
|
form_toc.fd \
|
||||||
form_url.fd
|
form_url.fd \
|
||||||
|
form_wrap.fd
|
||||||
|
|
||||||
libfdesign_la_SOURCES = $(SRCS:.fd=.C) $(SRCS:.fd=.h)
|
libfdesign_la_SOURCES = $(SRCS:.fd=.C) $(SRCS:.fd=.h)
|
||||||
|
|
||||||
|
@ -121,6 +121,17 @@ FDFIXC=${DIRNAME}/fdfixc.sed
|
|||||||
|
|
||||||
OUTPUT_FILE=${COUT}; INTRO_MESSAGE
|
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 <config.h>" >> ${COUT}
|
||||||
echo "#include \"forms_gettext.h\"" >> ${COUT}
|
echo "#include \"forms_gettext.h\"" >> ${COUT}
|
||||||
echo "#include \"gettext.h\"" >> ${COUT}
|
echo "#include \"gettext.h\"" >> ${COUT}
|
||||||
|
@ -12,97 +12,96 @@
|
|||||||
# It contains the instructions that sed requires to manipulate
|
# It contains the instructions that sed requires to manipulate
|
||||||
# the .c files produced by fdesign into a form usable by LyX
|
# 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
|
/generated with fdesign/d
|
||||||
|
/^\/\*-----/d
|
||||||
|
|
||||||
# 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.
|
|
||||||
#
|
|
||||||
# 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
|
# Replace "forms.h" by FORMS_H_LOCATION in the #include directives
|
||||||
s/#include \"forms\.h\"/#include FORMS_H_LOCATION/
|
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 );\
|
|
||||||
}\
|
|
||||||
|
|
||||||
}
|
# Pretty formatting; replace all leading whitespace with a tab
|
||||||
x
|
/^[ ]/s/^[ ]*/ /
|
||||||
}
|
|
||||||
# When the wrappers are here, delete to here
|
|
||||||
|
# Rename struct "FD_form_xxx" as "FD_xxx"
|
||||||
|
s/FD_form_\(.*\)/FD_\1/
|
||||||
|
|
||||||
|
|
||||||
# Rename the function create_form_form_xxx(void) as build_xxx()
|
# Rename the function create_form_form_xxx(void) as build_xxx()
|
||||||
s/\(.*\) \*create_form_form_\(.*\)\([(]void[)]\)/\1 * build_\2(void * parent)/
|
s/\(.*\) \*create_form_form_\(.*\)\([(]void[)]\)/\
|
||||||
|
\
|
||||||
|
\1 * build_\2(void * parent)/
|
||||||
|
|
||||||
# We use new/delete not malloc/free so change to suit
|
|
||||||
|
# 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/
|
||||||
|
|
||||||
|
|
||||||
|
# We use new/delete not malloc/free so change to suit.
|
||||||
s/\(\(FD_[^ ]*\) \*fdui =\).*sizeof(\*fdui))/\1 new \2/
|
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",
|
# For all lines containing "bmtable",
|
||||||
# replace "fl_add_button" with "fl_add_bmtable"
|
# replace "fl_add_button" with "fl_add_bmtable"
|
||||||
/bmtable/ s/fl_add_button/fl_add_bmtable/
|
/bmtable/ s/fl_add_button/fl_add_bmtable/
|
||||||
|
|
||||||
|
|
||||||
# For all lines containing "fl_" and a string _not_ containing |,
|
# For all lines containing "fl_" and a string _not_ containing |,
|
||||||
# replace the string with _(string)
|
# replace the string with _(string)
|
||||||
/fl_/ s/".[^|]*"/_(&)/
|
/fl_/ s/".[^|]*"/_(&)/
|
||||||
|
|
||||||
|
|
||||||
# For all lines containing "_shortcut" and a string containing |,
|
# For all lines containing "_shortcut" and a string containing |,
|
||||||
# replace the string with scex(_(string))
|
# replace the string with scex(_(string))
|
||||||
/_shortcut/ s/".*[|].*"/scex(_(&))/
|
/_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 |
|
# For all lines containing "fl_add" and a string containing |
|
||||||
# do several things.
|
# change so:
|
||||||
# Eg
|
# fdui->counter_zoom = obj = fl_add_counter(...,"Zoom %|#Z");
|
||||||
# fdui->counter_zoom = obj = fl_add_counter(FL_NORMAL_COUNTER,1,2,3,4,"Zoom %|#Z");
|
|
||||||
#
|
|
||||||
# becomes
|
# becomes
|
||||||
# fdui->counter_zoom = obj;
|
# c_str = _("Zoom %|#Z");
|
||||||
# {
|
# fdui->counter_zoom = obj = fl_add_counter(...,idex(c_str));
|
||||||
# // xgettext:no-c-format
|
# fl_set_button_shortcut(obj,scex(c_str),1);
|
||||||
# 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/{
|
/fl_add.*".*[|].*"/s/fdui\(.*\)"\(.*\)".*/c_str = _("\2");\
|
||||||
/".*[|].*"/{
|
fdui\1idex(c_str));\
|
||||||
|
fl_set_button_shortcut(obj,scex(c_str),1);/
|
||||||
|
|
||||||
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\
|
# gettext will get confused if the string contains a "%" unless the line is
|
||||||
\2/
|
# 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
|
# 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.
|
# autogeneration of the files so their pretty formatting got lost. Not anymore.
|
||||||
@ -113,4 +112,3 @@ s/,\([^ ]\)/, \1/g
|
|||||||
# while ensuring "...", "..." isn't affected.
|
# while ensuring "...", "..." isn't affected.
|
||||||
#
|
#
|
||||||
s/\("[^"]+,\) \("\)/\1\2/g
|
s/\("[^"]+,\) \("\)/\1\2/g
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
# It contains the instructions that sed requires to manipulate
|
# It contains the instructions that sed requires to manipulate
|
||||||
# the .h files produced by fdesign into a form usable by LyX
|
# the .h files produced by fdesign into a form usable by LyX
|
||||||
|
|
||||||
# Remove trailing whitespace.
|
# Pretty formatting; remove trailing whitespace.
|
||||||
s/[ ]*$//
|
s/[ ]*$//
|
||||||
|
|
||||||
|
|
||||||
@ -29,13 +29,12 @@ s/[ ]*$//
|
|||||||
|
|
||||||
|
|
||||||
# Immediately after line "#define FD_xxx_h_" that starts off the header file,
|
# 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
|
# #include "fdesign_base.h" and append the contents of file "extern.tmp".
|
||||||
# "extern.tmp". This latter is a sorted, unique list of any function
|
# This latter is a sorted, unique list of any function declarations.
|
||||||
# declarations.
|
|
||||||
/#define FD/{
|
/#define FD/{
|
||||||
a\
|
a\
|
||||||
\
|
\
|
||||||
#include "forms_fwd.h"\
|
#include "fdesign_base.h"\
|
||||||
|
|
||||||
r extern.tmp
|
r extern.tmp
|
||||||
}
|
}
|
||||||
@ -53,61 +52,54 @@ s/extern \(.*\) create_form_form_\(.*\)[(]void[)]/\1 build_\2(void *)/
|
|||||||
# Manipulate the structs:
|
# Manipulate the structs:
|
||||||
#
|
#
|
||||||
# Rewrite as
|
# Rewrite as
|
||||||
# typedef struct { struct FD_xxx {
|
# typedef struct { struct FD_xxx : public FD_base {
|
||||||
# FL_FORM *form_xxx; ~FD_xxx();
|
# FL_FORM *form_xxx; FL_OBJECT * some_obj;
|
||||||
# void *vdata; FL_FORM * form;
|
# void *vdata; ...
|
||||||
# char *cdata; FL_OBJECT * some_obj;
|
# char *cdata; };
|
||||||
# long ldata; ...
|
# long ldata;
|
||||||
# FL_OBJECT *some_obj; };
|
# FL_OBJECT *some_obj;
|
||||||
# ...
|
# ...
|
||||||
# } FD_xxx;
|
# } FD_xxx;
|
||||||
#
|
#
|
||||||
# This is detailed more closely below
|
# This is detailed more closely below
|
||||||
|
|
||||||
# Delete lines containing:
|
# We retain only those lines in the struct that start " FL_OBJECT *",
|
||||||
/typedef struct/d
|
# placing them in the hold space until the end of the struct is reached
|
||||||
/vdata/d
|
# and we can ascertain the struct's name.
|
||||||
/cdata/d
|
|
||||||
/ldata/d
|
|
||||||
|
|
||||||
# Place all lines containing FL_FORM and FL_OBJECT in the hold space, deleting
|
# All other lines are deleted:
|
||||||
# them from the pattern space.
|
/^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...
|
# For all lines starting with FL_OBJECT...
|
||||||
/^ FL_OBJECT/{
|
/^ FL_OBJECT/{
|
||||||
|
|
||||||
# 1. Perform a little pretty formatting.
|
# 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.
|
# 2. Append to the hold space and delete from the pattern space.
|
||||||
H
|
H; d
|
||||||
d
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# The struct is ended by "} FD_xxx;", so now's the time to paste back the
|
# The struct is ended by "} FD_xxx;", so now's the time to paste back the
|
||||||
# contents of the hold space.
|
# contents of the hold space.
|
||||||
/} FD_/{
|
/} FD_/{
|
||||||
# 1. Insert an empty line.
|
|
||||||
i\
|
|
||||||
|
|
||||||
# 2. Rewrite "} FD_xxx;" as "struct FD_xxx {" and append a d-tor.
|
# 1. Rewrite "} FD_xxx;" as "\nstruct FD_xxx : public FD_base {".
|
||||||
s/} \(.*\);/struct \1 {\
|
s/} \(.*\);/\
|
||||||
~\1();/
|
struct \1 : public FD_base {/
|
||||||
|
|
||||||
# 3. Paste the contents of the hold space beneath it.
|
# 2. The hold space contains the FL_OBJECT lines, preceded by a new line.
|
||||||
G
|
# 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 the "struct FD_xxx" line.
|
||||||
|
# and empty the hold space
|
||||||
|
G; h; s/.*//; x
|
||||||
|
|
||||||
# 4. Close the struct and append an empty line.
|
# 4. Close the struct and append an empty line.
|
||||||
a\
|
a\
|
||||||
|
Loading…
Reference in New Issue
Block a user