]> arthur.barton.de Git - bup.git/blobdiff - hsplit.c
Actually hash stuff, and add a basic 'make test'.
[bup.git] / hsplit.c
index 42d30c759688bda696f4f3756d9d06994bc2d008..d15da1cb4d19fb73a380c0dcd438af81728cd02c 100644 (file)
--- a/hsplit.c
+++ b/hsplit.c
@@ -22,9 +22,27 @@ static uint32_t stupidsum_add(uint32_t old, uint8_t drop, uint8_t add)
 }
 
 
+static void test_sums()
+{
+    uint32_t sum = 0;
+    int i;
+    
+    for (i = 0; i < WINDOWSIZE; i++)
+       sum = stupidsum_add(sum, 0, i%256);
+    uint32_t sum1 = sum;
+    
+    for (i = 0; i < WINDOWSIZE; i++)
+       sum = stupidsum_add(sum, i%256, i%256);
+    assert(sum1 == sum);
+    
+    for (i = 0; i < WINDOWSIZE; i++)
+       sum = stupidsum_add(sum, i%256, 0);
+    assert(sum == 0);
+}
+
+
 int main()
 {
-    printf("hello world\n");
     assert(rol(1,0) == 1);
     assert(rol(1,1) == 2);
     assert(rol(1,32) == 1);
@@ -34,10 +52,12 @@ int main()
     assert(rol(0x92345678, 34) == 0x48d159e2);
     assert(WINDOWSIZE >= 32);
     assert(BLOBSIZE >= 32);
+    test_sums();
     
     uint8_t buf[WINDOWSIZE];
     uint32_t sum = 0;
     int i = 0, count = 0, c;
+    FILE *pipe = NULL;
     
     memset(buf, 0, sizeof(buf));
     
@@ -46,19 +66,32 @@ int main()
        sum = stupidsum_add(sum, buf[i], c);
        buf[i] = c;
        
-       int cprint = (c >= 32 && c <= 126) ? c : '.';
-       printf("[%05X] %02X '%c' %08X\n", i, c, cprint, sum);
+       //int cprint = (c >= 32 && c <= 126) ? c : '.';
+       //fprintf(stderr, "[%05X] %02X '%c' %08X\n", i, c, cprint, sum);
        
        i = (i + 1) % WINDOWSIZE;
        count++;
        
        if ((sum & (BLOBSIZE-1)) == 0)
        {
-           printf("\nSPLIT @ %d (%d)\n\n", count, BLOBSIZE);
+           fprintf(stderr, "SPLIT @ %d (%d)\n", count, BLOBSIZE);
            count = i = 0;
            memset(buf, 0, sizeof(buf));
+           if (pipe)
+           {
+               fflush(stderr);
+               pclose(pipe);
+               pipe = NULL;
+           }
        }
+       
+       if (!pipe)
+           pipe = popen("git hash-object --stdin -w", "w");
+       fputc(c, pipe);
     }
     
+    if (pipe)
+       pclose(pipe);
+    
     return 0;
 }