--- a/sreplace.c Sat May 19 15:36:32 2007 +0200
+++ b/sreplace.c Tue May 29 18:49:39 2007 +0200
@@ -8,8 +8,9 @@
#include <assert.h>
#include <string.h>
-/* Kind of string parameters */
-static int hex_strings = 0;
+enum {
+ BUFFER_SIZE = 2048
+};
static FILE * input, * output;
@@ -42,7 +43,7 @@
*/
struct Buffer
{
- char *base;
+ unsigned char *base;
int filled;
int read;
int read_cmp;
@@ -84,6 +85,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;
@@ -97,6 +99,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;
@@ -190,6 +193,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;
}
@@ -198,6 +202,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;
}
@@ -209,17 +214,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)
{
@@ -303,4 +309,5 @@
output = stdout;
loop();
+ return 0;
}