[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 4/4] gui: Factor out duplicated code for executing and pastin
From: |
John Darrington |
Subject: |
Re: [PATCH 4/4] gui: Factor out duplicated code for executing and pasting syntax. |
Date: |
Sun, 5 Dec 2010 12:03:31 +0000 |
User-agent: |
Mutt/1.5.18 (2008-05-17) |
On Sat, Dec 04, 2010 at 11:37:38AM -0800, Ben Pfaff wrote:
Reducing code duplication is good on its own. This will also make it
easier in upcoming patches to swap out "getl_interface" with a new
structure, by eliminating most of the references to getl_interface.
+/* Executes null-terminated string SYNTAX as syntax.
+ Returns SYNTAX. */
+gchar *
+execute_syntax_string (gchar *syntax)
+{
+ struct getl_interface *sss = create_syntax_string_source (syntax);
+ execute_syntax (sss);
+ return syntax;
+}
+
+/* Executes null-terminated string SYNTAX as syntax.
+ Returns SYNTAX. */
+const gchar *
+execute_const_syntax_string (const gchar *syntax)
+{
+ return execute_syntax_string (CONST_CAST (gchar *, syntax));
+}
These functions can be written as:
/* Executes null-terminated string SYNTAX as syntax.
Returns SYNTAX. */
gchar *
execute_syntax_string (gchar *syntax)
{
execute_const_syntax_string (syntax);
return syntax;
}
/* Executes null-terminated string SYNTAX as syntax.
Returns SYNTAX. */
const gchar *
execute_const_syntax_string (const gchar *syntax)
{
execute_syntax (create_syntax_string_source (syntax));
return syntax;
}
.. which avoids the CONST_CAST, and a reference to getl_interface.
Optionally, you could make the second function return void, since
nowhere is its return value used.
J'
--
PGP Public key ID: 1024D/2DE827B3
fingerprint = 8797 A26D 0854 2EAB 0285 A290 8A67 719C 2DE8 27B3
See http://pgp.mit.edu or any PGP keyserver for public key.
signature.asc
Description: Digital signature
- [PATCH 0/4] More preparation for lexer replacment, Ben Pfaff, 2010/12/04
- [PATCH 3/4] command: Don't allow SORT as an abbreviation for SORT CASES., Ben Pfaff, 2010/12/04
- [PATCH 2/4] Remove the PROMPT, CPROMPT, and DPROMPT settings., Ben Pfaff, 2010/12/04
- [PATCH 1/4] Remove the NULLINE and ENDCMD settings., Ben Pfaff, 2010/12/04
- [PATCH 4/4] gui: Factor out duplicated code for executing and pasting syntax., Ben Pfaff, 2010/12/04
- Re: [PATCH 4/4] gui: Factor out duplicated code for executing and pasting syntax.,
John Darrington <=