genius r681 - in trunk: . help/C src
- From: jirka svn gnome org
- To: svn-commits-list gnome org
- Subject: genius r681 - in trunk: . help/C src
- Date: Tue, 23 Sep 2008 04:24:07 +0000 (UTC)
Author: jirka
Date: Tue Sep 23 04:24:07 2008
New Revision: 681
URL: http://svn.gnome.org/viewvc/genius?rev=681&view=rev
Log:
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
Modified:
trunk/ChangeLog
trunk/help/C/gel-function-list.xml
trunk/src/calc.h
trunk/src/funclib.c
trunk/src/genius.c
trunk/src/geniustests.txt
trunk/src/gnome-genius.c
Modified: trunk/help/C/gel-function-list.xml
==============================================================================
--- trunk/help/C/gel-function-list.xml (original)
+++ trunk/help/C/gel-function-list.xml Tue Sep 23 04:24:07 2008
@@ -64,6 +64,17 @@
<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 @@
</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 @@
</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 @@
</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 @@
</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>
Modified: trunk/src/calc.h
==============================================================================
--- trunk/src/calc.h (original)
+++ trunk/src/calc.h Tue Sep 23 04:24:07 2008
@@ -112,6 +112,9 @@
/* 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*/
Modified: trunk/src/funclib.c
==============================================================================
--- trunk/src/funclib.c (original)
+++ trunk/src/funclib.c Tue Sep 23 04:24:07 2008
@@ -5595,9 +5595,12 @@
}
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 @@
}
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 @@
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 @@
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;
Modified: trunk/src/genius.c
==============================================================================
--- trunk/src/genius.c (original)
+++ trunk/src/genius.c Tue Sep 23 04:24:07 2008
@@ -64,6 +64,8 @@
#include <termcap.h>
#endif
+#include <vicious.h>
+
/*Globals:*/
/*calculator state*/
@@ -187,6 +189,29 @@
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)
Modified: trunk/src/geniustests.txt
==============================================================================
--- trunk/src/geniustests.txt (original)
+++ trunk/src/geniustests.txt Tue Sep 23 04:24:07 2008
@@ -914,5 +914,11 @@
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
Modified: trunk/src/gnome-genius.c
==============================================================================
--- trunk/src/gnome-genius.c (original)
+++ trunk/src/gnome-genius.c Tue Sep 23 04:24:07 2008
@@ -449,6 +449,49 @@
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)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]