Commit 33e7ab90 authored by Jiri (George) Lebl's avatar Jiri (George) Lebl Committed by George Lebl

rename parse/eval to Parse and Evaluate to be more in line with my


Mon Sep 22 23:23:51 2008  Jiri (George) Lebl <jirka@5z.com>

	* src/funclib.c: rename parse/eval to Parse and Evaluate to be
	  more in line with my in-vogue naming in Genius (no need to
	  break the consistency even further)

	* src/calc.h, src/genius.c, src/gnome-genius.c, src/funclib.c:
	  Implement function AskString to interactively ask for a string.
	  Use a dialog in GUI mode and readline in command line mode

	* src/geniustests.txt: add some tests

	* help/C/gel-function-list.xml: update


svn path=/trunk/; revision=681
parent a047f9d7
Mon Sep 22 23:23:51 2008 Jiri (George) Lebl <jirka@5z.com>
* src/funclib.c: rename parse/eval to Parse and Evaluate to be
more in line with my in-vogue naming in Genius (no need to
break the consistency even further)
* src/calc.h, src/genius.c, src/gnome-genius.c, src/funclib.c:
Implement function AskString to interactively ask for a string.
Use a dialog in GUI mode and readline in command line mode
* src/geniustests.txt: add some tests
* help/C/gel-function-list.xml: update
Mon Sep 22 00:05:25 2008 Jiri (George) Lebl <jirka@5z.com>
* configure.in: raise version
......
......@@ -64,6 +64,17 @@ in the proper directory.</para>
<sect1 id="genius-gel-function-list-basic">
<title>Basic</title>
<variablelist>
<varlistentry id="gel-function-AskString">
<term>AskString</term>
<listitem>
<synopsis>AskString (query)</synopsis>
<para>Asks a question and lets the user enter a string which
it then returns. If the user cancels or closes the window, then
<constant>null</constant> is returned. The execution of the program
is blocked until the user responds.</para>
</listitem>
</varlistentry>
<varlistentry id="gel-function-Compose">
<term>Compose</term>
<listitem>
......@@ -89,6 +100,15 @@ in the proper directory.</para>
</listitem>
</varlistentry>
<varlistentry id="gel-function-Evaluate">
<term>Evaluate</term>
<listitem>
<synopsis>Evaluate (str)</synopsis>
<para>Parses and evaluates a string.</para>
</listitem>
</varlistentry>
<varlistentry id="gel-function-GetCurrentModulo">
<term>GetCurrentModulo</term>
<listitem>
......@@ -200,6 +220,15 @@ not consider <constant>null</constant> a matrix.</para>
</listitem>
</varlistentry>
<varlistentry id="gel-function-Parse">
<term>Parse</term>
<listitem>
<synopsis>Parse (str)</synopsis>
<para>Parses but does not evaluate a string. Note that certain
precomputation is done during the parsing stage.</para>
</listitem>
</varlistentry>
<varlistentry id="gel-function-SetFunctionFlags">
<term>SetFunctionFlags</term>
<listitem>
......@@ -244,14 +273,6 @@ is called inside a block that was evaluated using modular arithmetic (using <lit
</listitem>
</varlistentry>
<varlistentry id="gel-function-eval">
<term>eval</term>
<listitem>
<synopsis>eval (str)</synopsis>
<para>Parses and evaluates a string.</para>
</listitem>
</varlistentry>
<varlistentry id="gel-function-error">
<term>error</term>
<listitem>
......@@ -295,15 +316,6 @@ made into a string before being printed.</para>
</listitem>
</varlistentry>
<varlistentry id="gel-function-parse">
<term>parse</term>
<listitem>
<synopsis>parse (str)</synopsis>
<para>Parses but does not evaluate a string. Note that certain
precomputation is done during the parsing stage.</para>
</listitem>
</varlistentry>
<varlistentry id="gel-function-printn">
<term>printn</term>
<listitem>
......
......@@ -112,6 +112,9 @@ void gel_printout_infos (void);
/* implemented in the frontend (function can be NULL) */
void gel_call_help (const char *function);
/* implemented in the frontend (query can be NULL) */
char *gel_ask_string (const char *query);
void gel_help_on (const char *text);
/*these are parts of the above*/
......
......@@ -5595,9 +5595,12 @@ end_of_simpson:
}
static GelETree *
parse_op (GelCtx *ctx, GelETree * * a, gboolean *exception)
Parse_op (GelCtx *ctx, GelETree * * a, gboolean *exception)
{
if G_UNLIKELY ( ! check_argument_string (a, 0, "parse"))
if (a[0]->type == NULL_NODE)
return gel_makenum_null ();
if G_UNLIKELY ( ! check_argument_string (a, 0, "Parse"))
return NULL;
return gel_parseexp (a[0]->str.str,
......@@ -5609,11 +5612,14 @@ parse_op (GelCtx *ctx, GelETree * * a, gboolean *exception)
}
static GelETree *
eval_op (GelCtx *ctx, GelETree * * a, gboolean *exception)
Evaluate_op (GelCtx *ctx, GelETree * * a, gboolean *exception)
{
GelETree *et;
if G_UNLIKELY ( ! check_argument_string (a, 0, "parse"))
if (a[0]->type == NULL_NODE)
return gel_makenum_null ();
if G_UNLIKELY ( ! check_argument_string (a, 0, "Evaluate"))
return NULL;
et = gel_parseexp (a[0]->str.str,
......@@ -5626,6 +5632,22 @@ eval_op (GelCtx *ctx, GelETree * * a, gboolean *exception)
return eval_etree (ctx, et);
}
static GelETree *
AskString_op (GelCtx *ctx, GelETree * * a, gboolean *exception)
{
char *txt;
if G_UNLIKELY ( ! check_argument_string (a, 0, "AskString"))
return NULL;
txt = gel_ask_string (a[0]->str.str);
if (txt == NULL)
return gel_makenum_null ();
else
return gel_makenum_string_use (txt);
}
static GelETree *
set_FloatPrecision (GelETree * a)
......@@ -6325,8 +6347,10 @@ gel_funclib_addall(void)
FUNC (IsDefined, 1, "id", "basic", N_("Check if a variable or function is defined"));
FUNC (undefine, 1, "id", "basic", N_("Undefine a variable (including locals and globals)"));
FUNC (parse, 1, "str", "basic", N_("Parse a string (but do not execute)"));
FUNC (eval, 1, "str", "basic", N_("Parse and evaluate a string"));
FUNC (Parse, 1, "str", "basic", N_("Parse a string (but do not execute)"));
FUNC (Evaluate, 1, "str", "basic", N_("Parse and evaluate a string"));
FUNC (AskString, 1, "query", "basic", N_("Ask a question and return a string"));
FUNC (CompositeSimpsonsRule, 4, "f,a,b,n", "calculus", N_("Integration of f by Composite Simpson's Rule on the interval [a,b] with n subintervals with error of max(f'''')*h^4*(b-a)/180, note that n should be even"));
f->no_mod_all_args = 1;
......
......@@ -64,6 +64,8 @@
#include <termcap.h>
#endif
#include <vicious.h>
/*Globals:*/
/*calculator state*/
......@@ -187,6 +189,29 @@ gel_call_help (const char *function)
g_free (file);
}
char *
gel_ask_string (const char *query)
{
char *txt = NULL;
g_print ("\n%s\n", ve_sure_string (query));
if (use_readline) {
char *s = readline (">");
if (s != NULL) {
txt = g_strdup (s);
free (s);
}
} else {
char buf[256];
if (fgets (buf, sizeof (buf), stdin) != NULL) {
int len = strlen (buf);
if (buf[len-1] == '\n')
buf[len-1] = '\0';
txt = g_strdup (buf);
}
}
return txt;
}
static int
long_get_term_width (void)
......
......@@ -914,5 +914,11 @@ NullSpace([1,1;2,2]) [1;-1]
NullSpace([1,1;2,2;3,3]) [1;-1]
NullSpace([0,0;1,1;2,2;3,3]) [1;-1]
NullSpace([0,0;1,0;2,0;3,0]) [0;-1]
Parse("a+b") (a+b)
Parse(null)+1 ((null)+1)
Parse("x=1;x=x+1;x") ((x=1);(x=(x+1));x)
Evaluate("a+b") (a+b)
Evaluate(null)+1 ((null)+1)
Evaluate("x=1;x=x+1;x") 2
load "nullspacetest.gel" true
load "longtest.gel" true
......@@ -449,6 +449,49 @@ dialog_entry_activate (GtkWidget *e, gpointer data)
gtk_dialog_response (GTK_DIALOG (d), GTK_RESPONSE_OK);
}
char *
gel_ask_string (const char *query)
{
GtkWidget *d;
GtkWidget *e;
int ret;
char *txt = NULL;
d = gtk_dialog_new_with_buttons
(_("Genius"),
GTK_WINDOW (genius_window) /* parent */,
0 /* flags */,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OK, GTK_RESPONSE_OK,
NULL);
gtk_dialog_set_default_response (GTK_DIALOG (d), GTK_RESPONSE_OK);
gtk_dialog_set_has_separator (GTK_DIALOG (d), FALSE);
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (d)->vbox),
gtk_label_new (ve_sure_string(query)),
FALSE, FALSE, 0);
e = gtk_entry_new ();
g_signal_connect (G_OBJECT (e), "activate",
G_CALLBACK (dialog_entry_activate), d);
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (d)->vbox),
e,
FALSE, FALSE, 0);
gtk_widget_show_all (d);
ret = gtk_dialog_run (GTK_DIALOG (d));
if (ret == GTK_RESPONSE_OK) {
txt = gtk_entry_get_text (GTK_ENTRY (e));
txt = g_strdup (ve_sure_string (txt));
}
gtk_widget_destroy (d);
return txt;
}
static void
help_on_function (GtkWidget *menuitem, gpointer data)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment