Skip to content

Commit

Permalink
2002-07-24 Joshua Sled <jsled@asynchronous.org>
Browse files Browse the repository at this point in the history
	* src/scm/fin.scm: Made the exposed calcualtion functions output
	positive values.

	* src/gnome/window-main.c (gnc_main_window_create_menus): Added
	accelerators to SX-related menu items.

	* src/gnome/druid-loan.c: Primary change: actually create the
	Scheduled Transactions which are setup by the user.  Miscellaneous
	other cleanups, text, layout and consistency changes.

	* src/gnome/dialog-sxsincelast.c: Support handling of the
	instance-count in forward-looking transaction creation.  Simplfied
	some of the internal data-representation regarding lists of items
	to be created [removed autoCreateTuple, now uses toCreateTuple].
	Removed some DEBUGging output.  Handles setting up the implicit
	'i' variable.

	* src/gnome/dialog-sx-from-trans.c (sxftd_compute_sx): Create SXes
	with an appropriate initial instance-count value.

	* src/gnome/dialog-scheduledxaction.c
	(schedXact_editor_populate): Create SXes with an appropriate
	initial instance-count value.

	* src/engine/SchedXaction.[ch]: Added support for an
	instance-count, in order to support an implicit 'i' [of N]
	variable to SX formula/function processing.

	* src/engine/SX-ttinfo.c (gnc_ttsplitinfo_free): Made the
	ttsplitinfo_free'ing a bit safer.

	* src/calculation/expression_parser.c: Added support for
	parsing/handling quoted strings.  Intended to be parameters to
	functions.  Fixed bug regarding nested handling of strings in the
	parser.

	* src/backend/file/gnc-schedxaction-xml-v2.c: Added support for
	saving/restoring instance-count field of SXes.

	* src/app-utils/test/test-exp-parser.c
	(run_parser_test): Fixed pass/fail indication check.
	(test_parser): Added tests for string params to functions.

	* ChangeLog: Added entry I forgot from last time.

	* src/app-utils/gnc-exp-parser.c (func_op): Added support for
	typed parameters to functions; params are either numerics or
	strings.  Result of function is now parsed correctly.


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@7125 57a11ea4-9604-0410-9ed3-97b8803252fd
  • Loading branch information
jsled committed Jul 24, 2002
1 parent 2a990a6 commit 1352897
Show file tree
Hide file tree
Showing 19 changed files with 1,316 additions and 2,197 deletions.
61 changes: 61 additions & 0 deletions ChangeLog
@@ -1,3 +1,54 @@
2002-07-24 Joshua Sled <jsled@asynchronous.org>

* src/scm/fin.scm: Made the exposed calcualtion functions output
positive values.

* src/gnome/window-main.c (gnc_main_window_create_menus): Added
accelerators to SX-related menu items.

* src/gnome/druid-loan.c: Primary change: actually create the
Scheduled Transactions which are setup by the user. Miscellaneous
other cleanups, text, layout and consistency changes.

* src/gnome/dialog-sxsincelast.c: Support handling of the
instance-count in forward-looking transaction creation. Simplfied
some of the internal data-representation regarding lists of items
to be created [removed autoCreateTuple, now uses toCreateTuple].
Removed some DEBUGging output. Handles setting up the implicit
'i' variable.

* src/gnome/dialog-sx-from-trans.c (sxftd_compute_sx): Create SXes
with an appropriate initial instance-count value.

* src/gnome/dialog-scheduledxaction.c
(schedXact_editor_populate): Create SXes with an appropriate
initial instance-count value.

* src/engine/SchedXaction.[ch]: Added support for an
instance-count, in order to support an implicit 'i' [of N]
variable to SX formula/function processing.

* src/engine/SX-ttinfo.c (gnc_ttsplitinfo_free): Made the
ttsplitinfo_free'ing a bit safer.

* src/calculation/expression_parser.c: Added support for
parsing/handling quoted strings. Intended to be parameters to
functions. Fixed bug regarding nested handling of strings in the
parser.

* src/backend/file/gnc-schedxaction-xml-v2.c: Added support for
saving/restoring instance-count field of SXes.

* src/app-utils/test/test-exp-parser.c
(run_parser_test): Fixed pass/fail indication check.
(test_parser): Added tests for string params to functions.

* ChangeLog: Added entry I forgot from last time.

* src/app-utils/gnc-exp-parser.c (func_op): Added support for
typed parameters to functions; params are either numerics or
strings. Result of function is now parsed correctly.

2002-07-24 Christian Stimming <stimming@tuhh.de>

* src/import-export/hbci/glade/hbci.glade: Some HBCI GUI work --
Expand All @@ -13,6 +64,16 @@
* src/backend/file/gnc-backend-file.c: File permission fix by Matt
Brubeck <mbrubeck@cs.hmc.edu>

2002-07-12 Joshua Sled <jsled@asynchronous.org>

* src/gnome/glade/sched-xact.glade: Glade-side UI cleanup.

* src/gnome/druid-loan.c: Many updates; now uses GNCAccountSel,
more inter-page consistency checks. UI cleanup

* src/gnome-utils/gnc-account-sel.[ch]: Added; GTK combobox for
selecting an Account.

2002-07-11 Derek Atkins <derek@ihtfp.com>

* change gncEntry->account into gncEntry->invAccount and
Expand Down
32 changes: 28 additions & 4 deletions src/app-utils/gnc-exp-parser.c
Expand Up @@ -350,6 +350,8 @@ func_op( const char *fname,
{
SCM scmFn, scmArgs, scmTmp;
int i;
var_store *vs;
gchar *str;
gnc_numeric n, *result;
GString *realFnName;

Expand All @@ -365,15 +367,37 @@ func_op( const char *fname,
scmArgs = gh_list( SCM_UNDEFINED );
for ( i=0; i<argc; i++ ) {
/* cons together back-to-front. */
n = *(gnc_numeric*)argv[argc - i - 1];
scmTmp = gh_double2scm( gnc_numeric_to_double( n ) );
vs = (var_store*)argv[argc - i - 1];
switch ( vs->type ) {
case VST_NUMERIC:
n = *(gnc_numeric*)(vs->value);
scmTmp = gh_double2scm( gnc_numeric_to_double( n ) );
break;
case VST_STRING:
str = (char*)(vs->value);
scmTmp = gh_str2scm( str, strlen(str) );
break;
default:
/* FIXME: error */
printf( "argument %d not a numeric or string [type = %d]\n",
i, vs->type );
return NULL;
break; /* notreached */
}
scmArgs = gh_cons( scmTmp, scmArgs );
}
scmTmp = gh_apply( scmFn, scmArgs );

result = g_new0( gnc_numeric, 1 );
*result = double_to_gnc_numeric( gh_scm2double(scmTmp), 1,
GNC_DENOM_SIGFIG | (6<<8) );
*result = double_to_gnc_numeric( gh_scm2double(scmTmp),
GNC_DENOM_AUTO,
GNC_DENOM_SIGFIGS(6) | GNC_RND_ROUND );
/* I'm not sure why this explicit negation step is necessary, but it
* doesn't seem like it should be. */
if ( gh_scm2double( scmTmp ) < 0 ) {
*result = gnc_numeric_neg( *result );
}
/* FIXME: cleanup scmArgs = gh_list, cons'ed cells? */
return (void*)result;
}

Expand Down
49 changes: 34 additions & 15 deletions src/app-utils/test/test-exp-parser.c
Expand Up @@ -8,6 +8,8 @@
#include "gnc-numeric.h"
#include "test-stuff.h"

void real_main (int argc, char **argv);

static GList *tests = NULL;

typedef struct
Expand Down Expand Up @@ -62,12 +64,12 @@ run_parser_test (TestNode *node)
succeeded = gnc_exp_parser_parse (node->exp, &result, &error_loc);
{
int pass;
pass = succeeded;
pass ^= node->should_succeed;
pass = !pass;
printf( "%0.2f [%s]\n",
( ( pass && node->should_succeed ) ?
gnc_numeric_to_double( result ) : 0.0 ),
pass = (succeeded == node->should_succeed);
if ( pass && node->should_succeed ) {
pass &= gnc_numeric_equal( result, node->expected_result );
}
printf( "%0.4f [%s]\n",
gnc_numeric_to_double( result ),
(pass ? "PASS" : "FAIL" ) );
}

Expand Down Expand Up @@ -139,7 +141,7 @@ test_parser (void)
"- 42.72 + 13.32 + 15.48 + 23.4 + 115.4",
gnc_numeric_create(35897, 100) );

gh_eval_str( "(define (plus a b) (+ a b))" );
gh_eval_str( "(define (gnc:plus a b) (+ a b))" );
add_pass_test( "plus( 1 : 2 ) + 3", NULL, gnc_numeric_create( 6, 1 ) );
add_pass_test( "plus( 1 : 2 ) * 3", NULL, gnc_numeric_create( 9, 1 ) );
add_pass_test( "plus( 1 + 2 : 3 ) * 5", NULL, gnc_numeric_create( 30, 1 ) );
Expand All @@ -148,22 +150,39 @@ test_parser (void)
add_pass_test( "plus( plus( 1 : 2 ) : 3 )", NULL, gnc_numeric_create( 6, 1 ) );
add_pass_test( "plus( 4 : plus( plus( 1 : 2 ) : 3))", NULL, gnc_numeric_create( 10, 1 ) );

gh_eval_str( "(define (foo a b) (+ a b))" );
add_pass_test( "foo( 1 : 2 ) + 4", NULL, gnc_numeric_create( 7, 1 ) );
gh_eval_str( "(define (gnc:foo a b) (- a b))" );
add_pass_test( "foo( 1 : 2 ) + 4", NULL, gnc_numeric_create( 3, 1 ) );

add_pass_test( "foo( (1 + 2 * 3) : 4 ) + 5",
NULL, gnc_numeric_create( 16, 1 ) );
NULL, gnc_numeric_create( 8, 1 ) );
add_pass_test( "foo( 1 : 2 ) + foo( 3 : 4 ) + 5",
NULL, gnc_numeric_create( 15, 1 ) );
add_pass_test( "foo( a = 42 : foo( foo( 1 : 2 ) : 6 * 7 )) + a",
NULL, gnc_numeric_create( 129, 1 ) );
NULL, gnc_numeric_create( 3, 1 ) );
add_pass_test( "foo( a = 42 : foo( plus( 1 : 2 ) : 6 * 7 )) + a",
NULL, gnc_numeric_create( 123, 1 ) );

gh_eval_str( "(define (gnc:test_str str b)"
" (+ b (cond ((equal? str \"one\") 1)"
" ((equal? str \"two\") 2)"
" ((equal? str \"three\") 3)"
" (0))))" );
add_pass_test( "test_str( \"one\" : 1 )", NULL, gnc_numeric_create( 2, 1 ) );
add_pass_test( "test_str( \"two\" : 2 )", NULL, gnc_numeric_create( 4, 1 ) );
add_fail_test( "test_str( 3 : \"three\" )", NULL, 0 );
add_pass_test( "test_str( \"asdf\" : 1 )", NULL, gnc_numeric_create( 1, 1 ) );
add_fail_test( "\"asdf\" + 0", NULL, 0 );

gh_eval_str( "(define (gnc:blindreturn val) val)" );
add_pass_test( "blindreturn( 123.1 )", NULL, gnc_numeric_create( 1231, 10 ) );
add_pass_test( "blindreturn( 123.01 )", NULL, gnc_numeric_create( 12301, 100 ) );
add_pass_test( "blindreturn( 123.001 )", NULL, gnc_numeric_create( 123001, 1000 ) );

run_parser_tests ();

gnc_exp_parser_shutdown ();
success ("shutdown expression parser");
}

int
void
real_main (int argc, char **argv)
{
/* set_should_print_success (TRUE); */
Expand All @@ -176,5 +195,5 @@ int main( int argc, char **argv )
{
/* do things this way so we can test scheme function calls from expressions */
gh_enter( argc, argv, real_main );

return 0;
}
26 changes: 26 additions & 0 deletions src/backend/file/gnc-schedxaction-xml-v2.c
Expand Up @@ -59,6 +59,7 @@ static short module = MOD_SX;
* <sx:autoCreateNotify>n</sx:autoCreateNotify>
* <sx:advanceCreateDays>0</sx:advanceCreateDays>
* <sx:advanceRemindDays>5</sx:advanceRemindDays>
* <sx:instanceCount>100</sx:instanceCount>
* <sx:lastOccur>
* <gdate>2001-02-28</gdate>
* </sx:lastOccur>
Expand All @@ -80,6 +81,7 @@ static short module = MOD_SX;
* <sx:end type="date">
* <gdate>2004-03-20</gdate>
* </sx:end>
* <sx:instanceCount>100</sx:instanceCount>
* <sx:freq>
* <!-- freqspec tree -->
* </sx:freq>
Expand All @@ -88,6 +90,7 @@ static short module = MOD_SX;
* <sx:id type="guid">...</sx:id>
* <sx:name>Loan 2</sx:name>
* <sx:manual-conf>f</sx:manual-conf>
* <sx:instanceCount>100</sx:instanceCount>
* <sx:start>
* <gdate>2000-12-31</gdate>
* </sx:start>
Expand All @@ -113,6 +116,7 @@ static short module = MOD_SX;
#define SX_AUTOCREATE_NOTIFY "sx:autoCreateNotify"
#define SX_ADVANCE_CREATE_DAYS "sx:advanceCreateDays"
#define SX_ADVANCE_REMIND_DAYS "sx:advanceRemindDays"
#define SX_INSTANCE_COUNT "sx:instanceCount"
#define SX_START "sx:start"
#define SX_LAST "sx:last"
#define SX_NUM_OCCUR "sx:num-occur"
Expand All @@ -139,6 +143,7 @@ gnc_schedXaction_dom_tree_create(SchedXaction *sx)
xmlNodePtr ret;
xmlNodePtr fsNode;
GDate *date;
gint instCount;
const GUID *templ_acc_guid;

templ_acc_guid = xaccAccountGetGUID(sx->template_acct);
Expand All @@ -163,6 +168,10 @@ gnc_schedXaction_dom_tree_create(SchedXaction *sx)
xmlAddChild(ret, int_to_dom_tree(SX_ADVANCE_REMIND_DAYS,
sx->advanceRemindDays));

instCount = gnc_sx_get_instance_count( sx, NULL );
xmlAddChild( ret, int_to_dom_tree( SX_INSTANCE_COUNT,
instCount ) );

xmlAddChild( ret,
gdate_to_dom_tree( SX_START,
xaccSchedXactionGetStartDate(sx) ) );
Expand Down Expand Up @@ -318,6 +327,22 @@ sx_set_date( xmlNodePtr node, SchedXaction *sx,
return TRUE;
}

static
gboolean
sx_instcount_handler( xmlNodePtr node, gpointer sx_pdata )
{
struct sx_pdata *pdata = sx_pdata;
SchedXaction *sx = pdata->sx;
gint64 instanceNum;

if ( ! dom_tree_to_integer( node, &instanceNum ) ) {
return FALSE;
}

gnc_sx_set_instance_count( sx, instanceNum );
return TRUE;
}

static
gboolean
sx_start_handler( xmlNodePtr node, gpointer sx_pdata )
Expand Down Expand Up @@ -436,6 +461,7 @@ struct dom_tree_handler sx_dom_handlers[] = {
{ SX_AUTOCREATE_NOTIFY, sx_notify_handler, 1, 0 },
{ SX_ADVANCE_CREATE_DAYS, sx_advCreate_handler, 1, 0 },
{ SX_ADVANCE_REMIND_DAYS, sx_advRemind_handler, 1, 0 },
{ SX_INSTANCE_COUNT, sx_instcount_handler, 0, 0 },
{ SX_START, sx_start_handler, 1, 0 },
{ SX_LAST, sx_last_handler, 0, 0 },
{ SX_NUM_OCCUR, sx_numOccur_handler, 0, 0 },
Expand Down

0 comments on commit 1352897

Please sign in to comment.