[genius] Wed Jan 27 00:52:13 2010 Jiri (George) Lebl <jirka 5z com>



commit 0c6b8cda9b760852a4d673b4bc3ebb08c68d90d9
Author: Jiri (George) Lebl <jirka 5z com>
Date:   Wed Jan 27 00:52:18 2010 -0600

    Wed Jan 27 00:52:13 2010  Jiri (George) Lebl <jirka 5z com>
    
    	* src/calc.h, src/genius.c, src/gnome-genius.c, src/funclib.c:
    	  Implement AskButtons interactive function which asks the user to
    	  select from a list of buttons.
    
    	* src/eval.c: allow comparisons (only == and !=) with null.  We
    	  really want to treat null as an empty matrix.  null is only
    	  equal to null itself of course.
    
    	* src/geniustests.txt: add tests for null comparisons
    
    	* help/C/genius.xml, help/C/gel-function-list.xml: Document
    	  AskButtons

 ChangeLog                    |   15 +++++++++++++
 configure.in                 |    2 +-
 help/C/gel-function-list.xml |   14 ++++++++++++
 help/C/genius.xml            |    6 ++--
 src/calc.h                   |    5 +++-
 src/eval.c                   |   17 +++++++++------
 src/funclib.c                |   35 ++++++++++++++++++++++++++++++-
 src/genius.c                 |   44 ++++++++++++++++++++++++++++++++++++++-
 src/geniustests.txt          |   10 +++++++++
 src/gnome-genius.c           |   47 +++++++++++++++++++++++++++++++++++++++++-
 10 files changed, 180 insertions(+), 15 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 53c4866..1cd1e70 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+Wed Jan 27 00:52:13 2010  Jiri (George) Lebl <jirka 5z com>
+
+	* src/calc.h, src/genius.c, src/gnome-genius.c, src/funclib.c:
+	  Implement AskButtons interactive function which asks the user to
+	  select from a list of buttons.
+
+	* src/eval.c: allow comparisons (only == and !=) with null.  We
+	  really want to treat null as an empty matrix.  null is only
+	  equal to null itself of course.
+
+	* src/geniustests.txt: add tests for null comparisons
+
+	* help/C/genius.xml, help/C/gel-function-list.xml: Document
+	  AskButtons
+
 Wed Dec 23 15:41:42 2009  Jiri (George) Lebl <jirka 5z com>
 
 	* Release 1.0.9
diff --git a/configure.in b/configure.in
index 19b967a..70c0708 100644
--- a/configure.in
+++ b/configure.in
@@ -1,7 +1,7 @@
 AC_INIT(src/calc.c)
 
 AM_CONFIG_HEADER(config.h)
-AM_INIT_AUTOMAKE(genius,1.0.9)
+AM_INIT_AUTOMAKE(genius,1.0.10)
 
 dnl make sure we keep ACLOCAL_FLAGS around for maintainer builds to work
 AC_SUBST(ACLOCAL_AMFLAGS, "$ACLOCAL_FLAGS")
diff --git a/help/C/gel-function-list.xml b/help/C/gel-function-list.xml
index 4db8fbe..f978cff 100644
--- a/help/C/gel-function-list.xml
+++ b/help/C/gel-function-list.xml
@@ -64,6 +64,20 @@ in the proper directory.</para>
     <sect1 id="genius-gel-function-list-basic">
       <title>Basic</title>
       <variablelist>
+        <varlistentry id="gel-function-AskButtons">
+         <term>AskButtons</term>
+         <listitem>
+          <synopsis>AskButtons (query)</synopsis>
+          <synopsis>AskButtons (query, button1, ...)</synopsis>
+	  <para>Asks a question and presents a list of buttons to the user (or
+a menu of options in text mode).  Returns the 1-based index of the button
+pressed.  That is, returns 1 if the first button was pressed, 2 if the second
+button was pressed, and so on.  If the user closes the window (or simply hits
+enter in text mode), then <constant>null</constant> is returned.  The execution
+of the program is blocked until the user responds.</para>
+         </listitem>
+        </varlistentry>
+
         <varlistentry id="gel-function-AskString">
          <term>AskString</term>
          <listitem>
diff --git a/help/C/genius.xml b/help/C/genius.xml
index 760a4ad..296f41c 100644
--- a/help/C/genius.xml
+++ b/help/C/genius.xml
@@ -3,9 +3,9 @@
 "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd"; [
   <!ENTITY app "<application>Genius Mathematics Tool</application>">
   <!ENTITY appname "Genius">
-  <!ENTITY appversion "1.0.7">
+  <!ENTITY appversion "1.0.10">
   <!ENTITY manrevision "0.2.4">
-  <!ENTITY date "September 2009">
+  <!ENTITY date "January 2010">
 
   <!ENTITY legal SYSTEM "legal.xml">
 
@@ -28,7 +28,7 @@
     <title>&appname; Manual</title>       
 
     <copyright>
-      <year>1997-2009</year>
+      <year>1997-2010</year>
       <holder>Ji&#345;&iacute; (George) Lebl</holder>
     </copyright>
     <copyright>
diff --git a/src/calc.h b/src/calc.h
index 566f1fc..ca4c97a 100644
--- a/src/calc.h
+++ b/src/calc.h
@@ -1,5 +1,5 @@
 /* GENIUS Calculator
- * Copyright (C) 1997-2009 Jiri (George) Lebl
+ * Copyright (C) 1997-2010 Jiri (George) Lebl
  *
  * Author: Jiri (George) Lebl
  *
@@ -115,6 +115,9 @@ void gel_call_help (const char *function);
 /* implemented in the frontend (query can be NULL) */
 char *gel_ask_string (const char *query, const char *def);
 
+/* implemented in the frontend, buttons should be a nonempty list of strings */
+int gel_ask_buttons (const char *query, GSList *buttons);
+
 void gel_help_on (const char *text);
 
 /*these are parts of the above*/
diff --git a/src/eval.c b/src/eval.c
index a021c9c..7e0e7b3 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -1,5 +1,5 @@
 /* GENIUS Calculator
- * Copyright (C) 1997-2009 Jiri (George) Lebl
+ * Copyright (C) 1997-2010 Jiri (George) Lebl
  *
  * Author: Jiri (George) Lebl
  *
@@ -1490,6 +1490,9 @@ eqmatrix(GelETree *a, GelETree *b, int *error)
 					break;
 			}
 		}
+	} else if (a->type == GEL_NULL_NODE ||
+		   b->type == GEL_NULL_NODE) {
+		return a->type == b->type ? 1 : 0;
 	} else if(a->type == GEL_MATRIX_NODE) {
 		GelMatrixW *m = a->mat.matrix;
 		if G_UNLIKELY (gel_matrixw_width(m)>1 ||
@@ -3488,7 +3491,7 @@ iter_derefvarop(GelCtx *ctx, GelETree *n)
 	gel_makenum_bool_from(n,x);	\
 	return;
 
-/*returns 0 if all numeric, 1 if numeric/matrix, 2 if contains string, 3 otherwise*/
+/*returns 0 if all numeric (or bool if bool_ok), 1 if numeric/matrix/null, 2 if contains string, 3 otherwise*/
 static int
 arglevel (GelETree *r, int cnt, gboolean bool_ok)
 {
@@ -3497,12 +3500,12 @@ arglevel (GelETree *r, int cnt, gboolean bool_ok)
 	for(i=0;i<cnt;i++,r = r->any.next) {
 		if (r->type == GEL_VALUE_NODE)
 			continue;
-		if (bool_ok && r->type == GEL_BOOL_NODE)
+		else if (bool_ok && r->type == GEL_BOOL_NODE)
 			continue;
-
-		if(r->type==GEL_MATRIX_NODE)
-			level = level<1?1:level;
-		else if(r->type==GEL_STRING_NODE)
+		else if (r->type == GEL_MATRIX_NODE ||
+			 r->type == GEL_NULL_NODE)
+			level = level < 1 ? 1 : level;
+		else if (r->type == GEL_STRING_NODE)
 			level = 2;
 		else
 			return 3;
diff --git a/src/funclib.c b/src/funclib.c
index 45098c4..81ad8e5 100644
--- a/src/funclib.c
+++ b/src/funclib.c
@@ -1,5 +1,5 @@
 /* GENIUS Calculator
- * Copyright (C) 1997-2009 Jiri (George) Lebl
+ * Copyright (C) 1997-2010 Jiri (George) Lebl
  *
  * Author: Jiri (George) Lebl
  *
@@ -5753,6 +5753,38 @@ AskString_op (GelCtx *ctx, GelETree * * a, gboolean *exception)
 		return gel_makenum_string_use (txt);
 }
 
+static GelETree *
+AskButtons_op (GelCtx *ctx, GelETree * * a, gboolean *exception)
+{
+	GSList *buttons = NULL;
+	int i;
+	int ret;
+
+	if G_UNLIKELY ( ! check_argument_string (a, 0, "AskButtons"))
+		return NULL;
+
+	i = 1;
+	while (a != NULL && a[i] != NULL) {
+		if G_UNLIKELY ( ! check_argument_string (a, i, "AskButtons")) {
+			g_slist_foreach (buttons, (GFunc)g_free, NULL);
+			g_slist_free (buttons);
+			return NULL;
+		}
+		buttons = g_slist_append (buttons, g_strdup (a[i]->str.str));
+		i++;
+	}
+
+	ret = gel_ask_buttons (a[0]->str.str, buttons);
+
+	g_slist_foreach (buttons, (GFunc)g_free, NULL);
+	g_slist_free (buttons);
+	
+	if (ret < 0)
+		return gel_makenum_null ();
+	else
+		return gel_makenum_ui (ret);
+}
+
 
 static GelETree *
 set_FloatPrecision (GelETree * a)
@@ -6449,6 +6481,7 @@ gel_funclib_addall(void)
 	FUNC (Evaluate, 1, "str", "basic", N_("Parse and evaluate a string"));
 
 	VFUNC (AskString, 2, "query,...", "basic", N_("Ask a question and return a string.  Optionally pass in a default."));
+	VFUNC (AskButtons, 3, "query,button1,...", "basic", N_("Ask a question and present a list of buttons.  Returns the 1-based index of the button pressed (or null on failure)."));
 
 	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;
diff --git a/src/genius.c b/src/genius.c
index 0e5203f..bbc9559 100644
--- a/src/genius.c
+++ b/src/genius.c
@@ -1,5 +1,5 @@
 /* GENIUS Calculator
- * Copyright (C) 1997-2009 Jiri (George) Lebl
+ * Copyright (C) 1997-2010 Jiri (George) Lebl
  *
  * Author: Jiri (George) Lebl
  *
@@ -229,6 +229,48 @@ gel_ask_string (const char *query, const char *def)
 	return txt;
 }
 
+int
+gel_ask_buttons (const char *query, GSList *buttons)
+{
+	int ret;
+	GSList *li;
+	int i;
+	int max;
+
+reread_buttons:
+	g_print ("\n%s\n", ve_sure_string (query));
+	i = 1;
+	for (li = buttons; li != NULL; li = li->next) {
+		g_print ("%d) %s\n", i, ve_sure_string (li->data));
+		i++;
+	}
+	max = i-1;
+	if (use_readline) {
+		char *s;
+		s = readline (">");
+		ret = -1;
+		if ( ! ve_string_empty (s)) {
+			if (sscanf (s, "%d", &ret) != 1) {
+				ret = -1;
+			}
+		}
+	} else {
+		char buf[256];
+		ret = -1;
+		if (fgets (buf, sizeof (buf), stdin) != NULL) {
+			if (sscanf (buf, "%d", &ret) != 1) {
+				ret = -1;
+			}
+		}
+	}
+	if (ret == 0 || ret > max) {
+		g_print (_("Out of range!\n"));
+		goto reread_buttons;
+	}
+
+	return ret;
+}
+
 static int
 long_get_term_width (void)
 {
diff --git a/src/geniustests.txt b/src/geniustests.txt
index 7b59381..443b81c 100644
--- a/src/geniustests.txt
+++ b/src/geniustests.txt
@@ -979,6 +979,16 @@ J(4,2)								[2,1,0,0;0,2,1,0;0,0,2,1;0,0,0,2]
 J(10,0)==AuxilliaryUnitMatrix (10)				true
 [1,2,3;4,5;6]							[1,2,3;4,5,0;6,0,0]
 a=[1,2,3;4,5,6;7,8,9];[a,10;11,12]				[1,2,3,10;4,5,6,10;7,8,9,10;11,11,11,12]
+null==1								false
+null==[1,2,3]							false
+1==null								false
+[1,2,3]==null							false
+null==null							true
+null!=1								true
+null!=[1,2,3]							true
+1!=null								true
+[1,2,3]!=null							true
+null!=null							false
 load "nullspacetest.gel"					true
 load "longtest.gel"						true
 load "testprec.gel"						true
diff --git a/src/gnome-genius.c b/src/gnome-genius.c
index 934a314..59a2039 100644
--- a/src/gnome-genius.c
+++ b/src/gnome-genius.c
@@ -1,5 +1,5 @@
 /* GENIUS Calculator
- * Copyright (C) 1997-2009 Jiri (George) Lebl
+ * Copyright (C) 1997-2010 Jiri (George) Lebl
  *
  * Author: Jiri (George) Lebl
  *
@@ -735,6 +735,51 @@ dialog_entry_activate (GtkWidget *e, gpointer data)
 	gtk_dialog_response (GTK_DIALOG (d), GTK_RESPONSE_OK);
 }
 
+int
+gel_ask_buttons (const char *query, GSList *buttons)
+{
+	GtkWidget *d;
+	GtkWidget *box;
+	GSList *li;
+	int i;
+	int ret;
+
+	d = gtk_dialog_new_with_buttons
+		(_("Genius"),
+		 GTK_WINDOW (genius_window) /* parent */,
+		 0 /* flags */,
+		 NULL);
+
+	i = 1;
+	for (li = buttons; li != NULL; li = li->next) {
+		gtk_dialog_add_button (GTK_DIALOG (d),
+				       ve_sure_string (li->data),
+				       i);
+		i++;
+	}
+
+	box = gtk_vbox_new (FALSE, GENIUS_PAD);
+	gtk_container_set_border_width (GTK_CONTAINER (box), GENIUS_PAD);
+	gtk_box_pack_start (GTK_BOX (GTK_DIALOG (d)->vbox),
+			    box,
+			    TRUE, TRUE, 0);
+
+
+	gtk_dialog_set_has_separator (GTK_DIALOG (d), FALSE);
+	gtk_box_pack_start (GTK_BOX (box),
+			    gtk_label_new (ve_sure_string(query)),
+			    FALSE, FALSE, 0);
+
+	gtk_widget_show_all (d);
+	ret = ve_dialog_run_nonmodal (GTK_DIALOG (d));
+	gtk_widget_destroy (d);
+
+	if (ret < 0)
+		return -1;
+	else
+		return ret;
+}
+
 char *
 gel_ask_string (const char *query, const char *def)
 {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]