OSSP CVS Repository

ossp - Difference in ossp-pkg/sio/al_test.c versions 1.2 and 1.3
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [History

ossp-pkg/sio/al_test.c 1.2 -> 1.3

--- al_test.c    2002/10/14 12:32:16     1.2
+++ al_test.c    2002/10/14 13:34:25     1.3
@@ -7,17 +7,16 @@
 
 #define S(s) s, strlen(s)
 
-al_rc_t printchunk(al_chunk_t *alc, void *u)
+const char *fill(char *p, int n)
 {
-    char buf[40];
-    char   *p = al_chunk_ptr(alc,0);
-    size_t  n = al_chunk_len(alc);
-    int     k;
+    static char buf[4 * 80 + 1];
+    int k;
 
     k=0;
     while (n > 0 && k < sizeof(buf)-5) {
         if (isprint(*p)) {
-            buf[k++] = *p;
+            buf[k] = *p;
+            k += 1;
         } else {
             sprintf(buf+k,"<%2.2x>",*p);
             k += 4;
@@ -27,10 +26,26 @@
     }
     buf[k] = '\0';
 
-    printf("C: %08lx + %-6d = %s\n",
+    return (const char *)buf;
+}
+
+al_rc_t printchunk(al_chunk_t *alc, void *u)
+{
+    size_t len, pre, post;
+
+    len = al_chunk_len(alc);
+    pre  = 20; if (pre > len) pre = len;
+    post = 20; if (post > len-pre) post = len-pre;
+
+    printf("C: %08lx + %-6d = ",
         (long)al_chunk_ptr(alc, 0),
-        al_chunk_len(alc),
-        buf);
+        al_chunk_len(alc));
+    fputs(fill(al_chunk_ptr(alc,0),pre), stdout);
+    if (post > 0) {
+        fputs(" .. ", stdout);
+        fputs(fill(al_chunk_ptr(alc,len-post),post), stdout);
+    }
+    fputs("\n", stdout);
 
     return AL_OK;
 }
@@ -43,17 +58,22 @@
 
 void print(const char *tag, al_t *al)
 {
-    char buf[10000];
+    char *buf;
     size_t n, len;
 
-    printf("%s\n",tag);
     n = al_bytes(al);
-    if (n > sizeof(buf)) n = sizeof(buf);
+    buf = (char *)malloc(n);
+    if (buf == NULL) abort();
+
     al_flatten(al, 0, n, buf, &len);
+
+    printf("%s = %d of %d\n",tag,len,n);
     fwrite(">>", 2, 1, stdout);
     fwrite(buf, len, 1, stdout);
     fwrite("<<", 2, 1, stdout);
     printf("\n\n");
+
+    free(buf);
 }
 
 void checklen(al_t *al)
@@ -78,6 +98,7 @@
 
 int main()
 {
+    al_rc_t rc;
     al_t *al, *al2, *al3;
     char baf[] = "Mittendrin\n";
     int i;
@@ -96,23 +117,21 @@
 
     al_append_bytes(al3, S("HUHU WORLD\n"));
 
-
     DUMP("DATA",al);
     DUMP("BUFFER",al2);
     DUMP("REPLACEMENT", al3);
 
 #if 1
-    al_splice(al, 102, 200, al3, al2);
-#else
-    al_splice(al, 102, 200, NULL, NULL);
+    rc = al_splice(al, al_bytes(al)-500, 500, al3, al2);
 #endif
+    printf("splice result: %d (%s)\n\n",rc,al_error(rc));
 
     checklen(al);
     checklen(al2);
     checklen(al3);
 
     DUMP("SPLICED",al);
-    print("RESULT", al);
+    print("SPLICED", al);
 
     DUMP("BUFFER",al2);
     print("BUFFER", al2);

CVSTrac 2.0.1