Jeroen Demeyer on Thu, 01 Nov 2007 15:26:35 +0100


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

Patch: user warnings in GP


This proposed patch enables user warnings in GP with a new warning() command. The effect is like the error(), except that the script is not interrupted.

Note: the file 'warning' should go in src/functions/programming
Index: src/functions/programming/error
===================================================================
RCS file: /home/cvs/pari/src/functions/programming/error,v
retrieving revision 1.7
diff -u -r1.7 error
--- src/functions/programming/error	31 Mar 2007 13:49:48 -0000	1.7
+++ src/functions/programming/error	1 Nov 2007 14:17:44 -0000
@@ -14,7 +14,7 @@
 Prototype: vs*
 Help: error({str}*): abort script with error message str
 Description: 
- (?gen,...):void  pari_err(talker, "${2 format_string}"${2 format_args})
+ (?gen,...):void  pari_err(user, "${2 format_string}"${2 format_args})
 Doc: outputs its argument list (each of
  them interpreted as a string), then interrupts the running \kbd{gp} program,
  returning to the input prompt. For instance
Index: src/headers/paridecl.h
===================================================================
RCS file: /home/cvs/pari/src/headers/paridecl.h,v
retrieving revision 1.723
diff -u -r1.723 paridecl.h
--- src/headers/paridecl.h	30 Oct 2007 23:52:17 -0000	1.723
+++ src/headers/paridecl.h	1 Nov 2007 14:17:44 -0000
@@ -1060,6 +1060,7 @@
 void    bruterr(GEN x,char format,long dec);
 void    dbgGEN(GEN x, long nb);
 void    error0(GEN g);
+void    warn0(GEN g);
 void    etatpile(void);
 char*   expand_tilde(const char *s);
 int     file_is_binary(FILE *f);
Index: src/language/anal.h
===================================================================
RCS file: /home/cvs/pari/src/language/anal.h,v
retrieving revision 1.103
diff -u -r1.103 anal.h
--- src/language/anal.h	30 Oct 2007 11:33:51 -0000	1.103
+++ src/language/anal.h	1 Nov 2007 14:17:44 -0000
@@ -133,6 +133,7 @@
 enum { f_RAW, f_PRETTYMAT, f_PRETTYOLD, f_PRETTY, f_TEX };
 
 void error0(GEN g);
+void warn0(GEN g);
 void gpwritebin(const char *s, GEN x);
 void print   (GEN g);
 void print0(GEN g, long flag);
Index: src/language/es.c
===================================================================
RCS file: /home/cvs/pari/src/language/es.c,v
retrieving revision 1.265
diff -u -r1.265 es.c
--- src/language/es.c	30 Oct 2007 11:33:51 -0000	1.265
+++ src/language/es.c	1 Nov 2007 14:17:44 -0000
@@ -3480,6 +3480,8 @@
 
 void error0(GEN g) { pari_err(user, g); }
 
+void warn0(GEN g) { pari_warn(user, g); }
+
 static char *
 wr_check(const char *s) {
   char *t = expand_tilde(s);
Index: src/language/init.c
===================================================================
RCS file: /home/cvs/pari/src/language/init.c,v
retrieving revision 1.370
diff -u -r1.370 init.c
--- src/language/init.c	30 Oct 2007 11:33:51 -0000	1.370
+++ src/language/init.c	1 Nov 2007 14:17:44 -0000
@@ -976,25 +976,36 @@
   pariflush(); pariOut = pariErr;
   pariflush(); term_color(c_ERR);
 
-  if (gp_function_name)
-    pariprintf("  *** %s: %s", gp_function_name, errmessage[numerr]);
+  if (numerr == user)
+  {
+    GEN g = va_arg(ap, GEN);
+    pariprintf("  ###   user warning: ");
+    print0(g, f_RAW);
+    pariputs("\n");
+  }
   else
-    pariprintf("  ***   %s", errmessage[numerr]);
-  switch (numerr)
   {
-    case warnmem: case warner:
-      pariputc(' '); ch1=va_arg(ap, char*);
-      vpariputs(ch1,ap); pariputs(".\n");
-      break;
-
-    case warnprec:
-      vpariputs(" in %s; new prec = %ld\n",ap);
-      break;
+    if (gp_function_name)
+      pariprintf("  *** %s: %s", gp_function_name, errmessage[numerr]);
+    else
+      pariprintf("  ***   %s", errmessage[numerr]);
 
-    case warnfile:
-      ch1=va_arg(ap, char*);
-      pariprintf(" %s: %s\n", ch1, va_arg(ap, char*));
-      break;
+    switch (numerr)
+    {
+      case warnmem: case warner:
+        pariputc(' '); ch1=va_arg(ap, char*);
+        vpariputs(ch1,ap); pariputs(".\n");
+        break;
+  
+      case warnprec:
+        vpariputs(" in %s; new prec = %ld\n",ap);
+        break;
+  
+      case warnfile:
+        ch1=va_arg(ap, char*);
+        pariprintf(" %s: %s\n", ch1, va_arg(ap, char*));
+        break;
+    }
   }
   term_color(c_NONE); va_end(ap);
   pariOut = out;
Function: warning
Section: programming/specific
C-Name: warn0
Prototype: vs*
Help: warning({str}*): display warning message str
Description: 
 (?gen,...):void  pari_warn(user, "${2 format_string}"${2 format_args})
Doc: outputs the message ``user warning''
 and the argument list (each of them interpreted as a string).
 If colors are enabled, this warning will be in a different color,
 making it easy to distinguish.
 \bprog
 warning(n, " is very large, this might take a while!")
 @eprog\noindent
  % \syn{NO}