[Snowball-discuss] Patch to fix niggles in Snowball compiler

Olly Betts olly@survex.com
Sat Oct 12 13:30:01 2002


--+HP7ph2BbKc20aGI
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Here's a patch which fixes a few niggles in the Snowball compiler:

* It calls close() on FILE* which is deeply wrong (should be fclose) and
  close isn't ANSI C so may not be present.  I guess close checks that
  int representation of the pointer passed is valid, notices it isn't
  and fails with EBADF, which is why it works at all at the moment...

* "#include <memory.h>" is non-ANSI - string.h is the header for
  memmove() etc.

* It needs to include stdlib.h for malloc, free, etc.

* One of the build scripts tries to compile str.c, which isn't present.

I sent Richard a patch to fix these problems a week or so back, but he's
not responded (I think he's busy).  I've attached it here.

Cheers,
    Olly

--+HP7ph2BbKc20aGI
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="snowball.patch"

Only in p.orig: .space.c.swp
diff -ruP p.orig/driver.c p/driver.c
--- p.orig/driver.c	2002-03-05 16:53:21.000000000 +0000
+++ p/driver.c	2002-10-05 13:26:15.000000000 +0100
@@ -1,5 +1,6 @@
 
-#include <stdio.h>   /* main etc */
+#include <stdio.h>  /* for fprintf etc */
+#include <stdlib.h> /* for free */
 #include "header.h"
 
 /*-static int intof(char * s)
@@ -164,8 +165,8 @@
                     g = create_generator_c(a, o);
                     generate_program_c(g);
                     close_generator_c(g);
-                    close(o->output_c);
-                    close(o->output_h);
+                    fclose(o->output_c);
+                    fclose(o->output_h);
                 }
                 if (o->make_java) {
                     symbol * b = add_s_to_b(0, s);
@@ -175,7 +176,7 @@
                     g = create_generator_java(a, o);
                     generate_program_java(g);
                     close_generator_java(g);
-                    close(o->output_java);
+                    fclose(o->output_java);
                 }
             }
             close_analyser(a);
diff -ruP p.orig/generator.c p/generator.c
--- p.orig/generator.c	2002-07-22 11:45:16.000000000 +0100
+++ p/generator.c	2002-10-05 13:22:25.000000000 +0100
@@ -1,5 +1,6 @@
 
 #include <stdio.h> /* for fprintf etc */
+#include <stdlib.h> /* for free */
 #include "header.h"
 
 /* recursive use: */
diff -ruP p.orig/make-full p/make-full
--- p.orig/make-full	2002-02-22 10:00:06.000000000 +0000
+++ p/make-full	2002-10-05 13:23:56.000000000 +0100
@@ -2,4 +2,4 @@
 gcc -O -o X/snowball -pedantic -Wall -Wunused \
                      p/space.c p/sort.c p/tokeniser.c p/analyser.c \
                      p/generator.c p/driver.c \
-                     p/generator_java.c p/str.c
+                     p/generator_java.c
diff -ruP p.orig/space.c p/space.c
--- p.orig/space.c	2002-10-05 13:21:51.000000000 +0100
+++ p/space.c	2002-10-05 13:30:57.000000000 +0100
@@ -1,7 +1,7 @@
 
 #include <stdio.h>    /* for printf */
 #include <stdlib.h>   /* malloc, free */
-#include <memory.h>   /* memmove */
+#include <string.h>   /* memmove */
 
 #include "header.h"
 

--+HP7ph2BbKc20aGI--