[gimp] Applied changes from CVS version 1.15 of official version of TinyScheme.



commit 9541fe03872d15d049c95809fa50b97ce5791129
Author: Kevin Cozens <kcozens cvs gnome org>
Date:   Fri Aug 7 16:25:31 2009 -0400

    Applied changes from CVS version 1.15 of official version of TinyScheme.
    Changed to always use snprintf (Patch due to Ramiro bsd1628).

 plug-ins/script-fu/tinyscheme/scheme-private.h |    4 +-
 plug-ins/script-fu/tinyscheme/scheme.c         |  112 +++++++++++-------------
 2 files changed, 55 insertions(+), 61 deletions(-)
---
diff --git a/plug-ins/script-fu/tinyscheme/scheme-private.h b/plug-ins/script-fu/tinyscheme/scheme-private.h
index 4b01ad1..89ba365 100644
--- a/plug-ins/script-fu/tinyscheme/scheme-private.h
+++ b/plug-ins/script-fu/tinyscheme/scheme-private.h
@@ -117,7 +117,9 @@ char    gc_verbose;      /* if gc_verbose is not zero, print gc status */
 char    no_memory;       /* Whether mem. alloc. has failed */
 
 #define LINESIZE 1024
-char    strbuff[LINESIZE];
+char    linebuff[LINESIZE];
+#define STRBUFFSIZE 256
+char    strbuff[STRBUFFSIZE];
 
 FILE *tmpfp;
 int tok;
diff --git a/plug-ins/script-fu/tinyscheme/scheme.c b/plug-ins/script-fu/tinyscheme/scheme.c
index 327ddb9..26dc30f 100644
--- a/plug-ins/script-fu/tinyscheme/scheme.c
+++ b/plug-ins/script-fu/tinyscheme/scheme.c
@@ -38,6 +38,7 @@
 #if USE_MATH
 # include <math.h>
 #endif
+
 #include <limits.h>
 #include <float.h>
 #include <ctype.h>
@@ -131,7 +132,7 @@ static int utf8_stricmp(const char *s1, const char *s2)
 #endif
 
 #ifndef prompt
-# define prompt "> "
+# define prompt "ts> "
 #endif
 
 #ifndef InitFile
@@ -1133,7 +1134,7 @@ INTERFACE pointer gensym(scheme *sc) {
      char name[40];
 
      for(; sc->gensym_cnt<LONG_MAX; sc->gensym_cnt++) {
-          sprintf(name,"gensym-%ld",sc->gensym_cnt);
+          snprintf(name,40,"gensym-%ld",sc->gensym_cnt);
 
           /* first check oblist */
           x = oblist_find_by_name(sc, name);
@@ -1218,21 +1219,21 @@ static pointer mk_atom(scheme *sc, char *q) {
 /* make constant */
 static pointer mk_sharp_const(scheme *sc, char *name) {
      long    x;
-     char    tmp[256];
+     char    tmp[STRBUFFSIZE];
 
      if (!strcmp(name, "t"))
           return (sc->T);
      else if (!strcmp(name, "f"))
           return (sc->F);
      else if (*name == 'o') {/* #o (octal) */
-          sprintf(tmp, "0%s", name+1);
+          snprintf(tmp, STRBUFFSIZE, "0%s", name+1);
           sscanf(tmp, "%lo", &x);
           return (mk_integer(sc, x));
      } else if (*name == 'd') {    /* #d (decimal) */
           sscanf(name+1, "%ld", &x);
           return (mk_integer(sc, x));
      } else if (*name == 'x') {    /* #x (hex) */
-          sprintf(tmp, "0x%s", name+1);
+          snprintf(tmp, STRBUFFSIZE, "0x%s", name+1);
           sscanf(tmp, "%lx", &x);
           return (mk_integer(sc, x));
      } else if (*name == 'b') {    /* #b (binary) */
@@ -1250,7 +1251,7 @@ static pointer mk_sharp_const(scheme *sc, char *name) {
                c='\t';
      } else if(name[1]=='x' && name[2]!=0) {
           int c1=0;
-          if(sscanf(name+2,"%x",&c1)==1 && c1<256) {
+          if(sscanf(name+2,"%x",&c1)==1 && c1 < UCHAR_MAX) {
                c=c1;
           } else {
                return sc->NIL;
@@ -1387,7 +1388,7 @@ static void gc(scheme *sc, pointer a, pointer b) {
 
   if (sc->gc_verbose) {
     char msg[80];
-    sprintf(msg,"done: %ld cells were recovered.\n", sc->fcells);
+    snprintf(msg,80,"done: %ld cells were recovered.\n", sc->fcells);
     putstr(sc,msg);
   }
 }
@@ -1559,7 +1560,7 @@ static void port_close(scheme *sc, pointer p, int flag) {
 static gunichar basic_inchar(port *pt) {
   int  len;
 
-  if(pt->kind&port_file) {
+  if(pt->kind & port_file) {
     unsigned char utf8[7];
     int  c;
     int  i;
@@ -1607,8 +1608,8 @@ static gunichar basic_inchar(port *pt) {
           }
       }
   } else {
-    if(*pt->rep.string.curr==0
-       || pt->rep.string.curr==pt->rep.string.past_the_end) {
+    if(*pt->rep.string.curr == 0 ||
+       pt->rep.string.curr == pt->rep.string.past_the_end) {
       return EOF;
     } else {
       gunichar c;
@@ -1640,17 +1641,17 @@ static gunichar inchar(scheme *sc) {
   gunichar c;
   port *pt;
  again:
-  pt=sc->inport->_object._port;
+  pt = sc->inport->_object._port;
   if(pt->kind&port_file)
   {
     if (sc->bc_flag)
       c = sc->backchar[--sc->bc_flag];
     else
-      c=basic_inchar(pt);
+      c = basic_inchar(pt);
   }
   else
-    c=basic_inchar(pt);
-  if(c==EOF && sc->inport==sc->loadport && sc->file_i!=0) {
+    c = basic_inchar(pt);
+  if(c == EOF && sc->inport == sc->loadport && sc->file_i != 0) {
     file_pop(sc);
     if(sc->nesting!=0) {
       return EOF;
@@ -1764,16 +1765,6 @@ static char *readstr_upto(scheme *sc, char *delim) {
   gunichar c_prev = 0;
   int  len = 0;
 
-#if 0
-  while (!is_one_of(delim, (*p++ = inchar(sc))))
-      ;
-  if(p==sc->strbuff+2 && p[-2]=='\\') {
-    *p=0;
-  } else {
-    backchar(sc,p[-1]);
-    *--p = '\0';
-  }
-#else
   do {
     c_prev = c;
     c = inchar(sc);
@@ -1781,14 +1772,13 @@ static char *readstr_upto(scheme *sc, char *delim) {
     p += len;
   } while (c && !is_one_of(delim, c));
 
-  if(p==sc->strbuff+2 && c_prev=='\\')
+  if(p == sc->strbuff+2 && c_prev == '\\')
     *p = '\0';
   else
   {
     backchar(sc,c);    /* put back the delimiter */
     p[-len] = '\0';
   }
-#endif
   return sc->strbuff;
 }
 
@@ -1802,7 +1792,7 @@ static pointer readstrexp(scheme *sc) {
 
   for (;;) {
     c=inchar(sc);
-    if(c==EOF || p-sc->strbuff>sizeof(sc->strbuff)-1) {
+    if(c == EOF || p-sc->strbuff > sizeof(sc->strbuff)-1) {
       return sc->F;
     }
     switch(state) {
@@ -2066,14 +2056,13 @@ static void atom2str(scheme *sc, pointer l, int f, char **pp, int *plen) {
           p = "#<EOF>";
      } else if (is_port(l)) {
           p = sc->strbuff;
-          strcpy(p, "#<PORT>");
+          snprintf(p, STRBUFFSIZE, "#<PORT>");
      } else if (is_number(l)) {
           p = sc->strbuff;
           if(num_is_integer(l)) {
-               sprintf(p, "%ld", ivalue_unchecked(l));
+               snprintf(p, STRBUFFSIZE, "%ld", ivalue_unchecked(l));
           } else {
-               g_ascii_formatd (p, sizeof (sc->strbuff), "%.10g",
-                                rvalue_unchecked(l));
+               snprintf(p, STRBUFFSIZE, "%.10g", rvalue_unchecked(l));
           }
      } else if (is_string(l)) {
           if (!f) {
@@ -2094,33 +2083,36 @@ static void atom2str(scheme *sc, pointer l, int f, char **pp, int *plen) {
           } else {
                switch(c) {
                case ' ':
-                    sprintf(p,"#\\space"); break;
+                    snprintf(p,STRBUFFSIZE,"#\\space"); break;
                case '\n':
-                    sprintf(p,"#\\newline"); break;
+                    snprintf(p,STRBUFFSIZE,"#\\newline"); break;
                case '\r':
-                    sprintf(p,"#\\return"); break;
+                    snprintf(p,STRBUFFSIZE,"#\\return"); break;
                case '\t':
-                    sprintf(p,"#\\tab"); break;
+                    snprintf(p,STRBUFFSIZE,"#\\tab"); break;
                default:
 #if USE_ASCII_NAMES
                     if(c==127) {
-                         strcpy(p,"#\\del"); break;
+                         snprintf(p,STRBUFFSIZE,"#\\del");
+                         break;
                     } else if(c<32) {
-                         strcpy(p,"#\\"); strcat(p,charnames[c]); break;
+                         snprintf(p,STRBUFFSIZE,"#\\%s", charnames[c]);
+                         break;
                     }
 #else
                     if(c<32) {
-                      sprintf(p,"#\\x%x",c); break;
+                      snprintf(p,STRBUFFSIZE,"#\\x%x",c); break;
                     }
 #endif
-                    sprintf(p,"#\\%c",c); break;
+                    snprintf(p,STRBUFFSIZE,"#\\x%c",c); break;
                }
           }
      } else if (is_symbol(l)) {
           p = symname(l);
      } else if (is_proc(l)) {
           p = sc->strbuff;
-          sprintf(p, "#<%s PROCEDURE %ld>", procname(l),procnum(l));
+          snprintf(p,STRBUFFSIZE,"#<%s PROCEDURE %ld>",
+                   procname(l),procnum(l));
      } else if (is_macro(l)) {
           p = "#<MACRO>";
      } else if (is_closure(l)) {
@@ -2129,7 +2121,7 @@ static void atom2str(scheme *sc, pointer l, int f, char **pp, int *plen) {
           p = "#<PROMISE>";
      } else if (is_foreign(l)) {
           p = sc->strbuff;
-          sprintf(p, "#<FOREIGN PROCEDURE %ld>", procnum(l));
+          snprintf(p,STRBUFFSIZE,"#<FOREIGN PROCEDURE %ld>", procnum(l));
      } else if (is_continuation(l)) {
           p = "#<CONTINUATION>";
      } else {
@@ -2932,7 +2924,7 @@ static pointer opexe_0(scheme *sc, enum scheme_opcodes op) {
                s_goto(sc,OP_BEGIN);
           }
      default:
-          sprintf(sc->strbuff, "%d: illegal operator", sc->op);
+          snprintf(sc->strbuff,STRBUFFSIZE,"%d: illegal operator", sc->op);
           Error_0(sc,sc->strbuff);
      }
      return sc->T;
@@ -3142,7 +3134,7 @@ static pointer opexe_1(scheme *sc, enum scheme_opcodes op) {
           s_goto(sc,OP_APPLY);
 
      default:
-          sprintf(sc->strbuff, "%d: illegal operator", sc->op);
+          snprintf(sc->strbuff,STRBUFFSIZE,"%d: illegal operator", sc->op);
           Error_0(sc,sc->strbuff);
      }
      return sc->T;
@@ -3607,7 +3599,7 @@ static pointer opexe_2(scheme *sc, enum scheme_opcodes op) {
      }
 
      default:
-          sprintf(sc->strbuff, "%d: illegal operator", sc->op);
+          snprintf(sc->strbuff,STRBUFFSIZE,"%d: illegal operator", sc->op);
           Error_0(sc,sc->strbuff);
      }
      return sc->T;
@@ -3761,7 +3753,7 @@ static pointer opexe_3(scheme *sc, enum scheme_opcodes op) {
      case OP_EQV:        /* eqv? */
           s_retbool(eqv(car(sc->args), cadr(sc->args)));
      default:
-          sprintf(sc->strbuff, "%d: illegal operator", sc->op);
+          snprintf(sc->strbuff,STRBUFFSIZE,"%d: illegal operator", sc->op);
           Error_0(sc,sc->strbuff);
      }
      return sc->T;
@@ -4308,7 +4300,7 @@ static pointer opexe_5(scheme *sc, enum scheme_opcodes op) {
      }
 
      default:
-          sprintf(sc->strbuff, "%d: illegal operator", sc->op);
+          snprintf(sc->strbuff,STRBUFFSIZE,"%d: illegal operator", sc->op);
           Error_0(sc,sc->strbuff);
 
      }
@@ -4363,7 +4355,7 @@ static pointer opexe_6(scheme *sc, enum scheme_opcodes op) {
      case OP_MACROP:          /* macro? */
           s_retbool(is_macro(car(sc->args)));
      default:
-          sprintf(sc->strbuff, "%d: illegal operator", sc->op);
+          snprintf(sc->strbuff,STRBUFFSIZE,"%d: illegal operator", sc->op);
           Error_0(sc,sc->strbuff);
      }
      return sc->T; /* NOTREACHED */
@@ -4450,24 +4442,24 @@ static void Eval_Cycle(scheme *sc, enum scheme_opcodes op) {
   for (;;) {
     op_code_info *pcd=dispatch_table+sc->op;
     if (pcd->name!=0) { /* if built-in function, check arguments */
-      char msg[512];
+      char msg[STRBUFFSIZE];
       int ok=1;
       int n=list_length(sc,sc->args);
 
       /* Check number of arguments */
       if(n<pcd->min_arity) {
         ok=0;
-        sprintf(msg,"%s: needs%s %d argument(s)",
-                pcd->name,
-                pcd->min_arity==pcd->max_arity?"":" at least",
-                pcd->min_arity);
+        snprintf(msg, STRBUFFSIZE, "%s: needs%s %d argument(s)",
+                 pcd->name,
+                 pcd->min_arity==pcd->max_arity?"":" at least",
+                 pcd->min_arity);
       }
       if(ok && n>pcd->max_arity) {
         ok=0;
-        sprintf(msg,"%s: needs%s %d argument(s)",
-                pcd->name,
-                pcd->min_arity==pcd->max_arity?"":" at most",
-                pcd->max_arity);
+        snprintf(msg, STRBUFFSIZE, "%s: needs%s %d argument(s)",
+                 pcd->name,
+                 pcd->min_arity==pcd->max_arity?"":" at most",
+                 pcd->max_arity);
       }
       if(ok) {
         if(pcd->arg_tests_encoding!=0) {
@@ -4496,10 +4488,10 @@ static void Eval_Cycle(scheme *sc, enum scheme_opcodes op) {
           } while(i<n);
           if(i<n) {
             ok=0;
-            sprintf(msg,"%s: argument %d must be: %s",
-                    pcd->name,
-                    i+1,
-                    tests[j].kind);
+            snprintf(msg, STRBUFFSIZE, "%s: argument %d must be: %s",
+                     pcd->name,
+                     i+1,
+                     tests[j].kind);
           }
         }
       }



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