Fixed a EOF problem (char -> unsigned char).
authorlbatlle@npdl268.bpo.hp.com
Wed, 23 May 2007 12:21:03 +0200
changeset 3 edae5c16989e
parent 0 31bc1c76aa85
child 4 576167dd9de2
Fixed a EOF problem (char -> unsigned char).
sreplace.c
--- a/sreplace.c	Fri May 18 18:59:39 2007 +0200
+++ b/sreplace.c	Wed May 23 12:21:03 2007 +0200
@@ -2,8 +2,9 @@
 #include <assert.h>
 #include <string.h>
 
-/* Kind of string parameters */
-static int hex_strings = 0;
+enum {
+  BUFFER_SIZE = 2048
+};
 
 static FILE * input, * output;
 
@@ -36,7 +37,7 @@
 */
 struct Buffer
 {
-  char *base;
+  unsigned char *base;
   int filled;
   int read;
   int read_cmp;
@@ -78,6 +79,7 @@
   if (blocksize > 0)
   {
     res = fread(b->base + b->filled, 1, blocksize, input);
+    /*res = read(0, b->base + b->filled, blocksize);*/
     /*fprintf(stderr, "fread1 %i bytes (should %i).\n", res, blocksize);*/
     size -= res;
     b->filled = (b->filled + res) % b->size;
@@ -91,6 +93,7 @@
   {
     blocksize = min(b->read - 1, size);
     res = fread(b->base, 1, blocksize, input);
+    /*res = read(0, b->base, blocksize);*/
     /*fprintf(stderr, "fread2 %i bytes.\n", res);*/
     size -= res;
     b->filled = (b->filled + res) % b->size;
@@ -184,6 +187,7 @@
       if (cmp_state.matched == cmp_state.str->length)
       {
         fwrite(new_str.ptr, 1, new_str.length, output);
+        /*write(1, new_str.ptr, new_str.length);*/
         read_advance(b, cmp_state.matched);
         cmp_state.matched = 0;
       }
@@ -192,6 +196,7 @@
       int c;
       c = getc_real(b); /* Will not be EOF. read_cmp is forwarder. */
       fputc(c, output);
+      /*write(1, &c, 1);*/
       cmp_state.matched = 0;
       b->read_cmp = b->read;
     }
@@ -203,17 +208,18 @@
   int c;
   while((c = getc_real(b)) != EOF)
       fputc(c, output);
+      /*write(1, &c, 1);*/
 }
 
 static void loop()
 {
   struct Buffer b;
 
-  b.base = (char *) malloc(2048);
+  b.base = (unsigned char *) malloc(BUFFER_SIZE);
   b.read = 0;
   b.read_cmp = 0;
   b.filled = 0;
-  b.size = 2048;
+  b.size = BUFFER_SIZE;
 
   while(file_read_more(&b) > 0)
   {
@@ -297,4 +303,5 @@
   output = stdout;
 
   loop();
+  return 0;
 }