chiark / gitweb /
Take advantage of the new dynamic string macros.
authormdw <mdw>
Fri, 21 May 1999 22:14:30 +0000 (22:14 +0000)
committermdw <mdw>
Fri, 21 May 1999 22:14:30 +0000 (22:14 +0000)
base64.c
dstr.c
testrig.c

index 5f5009a9a86854eb71b5040f86fcd0e6269763a1..10ce91e5c96f98b57e005f9c903171bafb59fd8e 100644 (file)
--- a/base64.c
+++ b/base64.c
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: base64.c,v 1.2 1999/05/18 21:45:27 mdw Exp $
+ * $Id: base64.c,v 1.3 1999/05/21 22:14:30 mdw Exp $
  *
  * Base64 encoding and decoding.
  *
@@ -30,6 +30,9 @@
 /*----- Revision history --------------------------------------------------*
  *
  * $Log: base64.c,v $
+ * Revision 1.3  1999/05/21 22:14:30  mdw
+ * Take advantage of the new dynamic string macros.
+ *
  * Revision 1.2  1999/05/18 21:45:27  mdw
  * Allow Base64 encode and decode of arbitrary rubbish.
  *
@@ -251,12 +254,11 @@ void base64_init(base64_ctx *ctx)
 int main(int argc, char *argv[])
 {
   unsigned char buf[BUFSIZ];
-  dstr d;
+  dstr d = DSTR_INIT;
   base64_ctx ctx;
   void (*proc)(base64_ctx *, const unsigned char *, size_t, dstr *);
   size_t sz;
 
-  dstr_create(&d);
   base64_init(&ctx);
 
   if (argc > 1 && strcmp(argv[1], "-d") == 0)
diff --git a/dstr.c b/dstr.c
index 6304351ea64eb8cab0ebf9866bdd7b1290c8611a..fe65ebebed3064119c7b7502e92e06c18e6da0d7 100644 (file)
--- a/dstr.c
+++ b/dstr.c
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: dstr.c,v 1.6 1999/05/21 08:38:33 mdw Exp $
+ * $Id: dstr.c,v 1.7 1999/05/21 22:14:30 mdw Exp $
  *
  * Handle dynamically growing strings
  *
@@ -30,6 +30,9 @@
 /*----- Revision history --------------------------------------------------*
  *
  * $Log: dstr.c,v $
+ * Revision 1.7  1999/05/21 22:14:30  mdw
+ * Take advantage of the new dynamic string macros.
+ *
  * Revision 1.6  1999/05/21 08:38:33  mdw
  * Implement some more functions in terms of macros.
  *
@@ -205,11 +208,11 @@ int dstr_vputf(dstr *d, const char *p, va_list ap)
   const char *q = p;
   size_t n = d->len;
   size_t sz;
+  dstr dd = DSTR_INIT;
 
   while (*p) {
     unsigned f;
     int wd, prec;
-    dstr dd;
 
     enum {
       f_short = 1,
@@ -233,7 +236,6 @@ int dstr_vputf(dstr *d, const char *p, va_list ap)
 
     /* --- Sort out the various silly flags and things --- */
 
-    dstr_create(&dd);
     DPUTC(&dd, '%');
     f = 0;
     sz = DSTR_PUTFSTEP;
@@ -396,13 +398,14 @@ int dstr_vputf(dstr *d, const char *p, va_list ap)
     }
 
   formatted:
-    dstr_destroy(&dd);
+    DRESET(&dd);
     q = ++p;
   }
 
   DPUTM(d, q, p - q);
 finished:
   DPUTZ(d);
+  DDESTROY(&dd);
   return (d->len - n);
 }
 
index 01ffa8413dde9046bb3aa35e0e8b847bee0a782b..95aca952591bedd959cbe37494a4878b24e3e2c5 100644 (file)
--- a/testrig.c
+++ b/testrig.c
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: testrig.c,v 1.4 1999/05/19 19:02:17 mdw Exp $
+ * $Id: testrig.c,v 1.5 1999/05/21 22:14:30 mdw Exp $
  *
  * Generic test driver
  *
@@ -30,6 +30,9 @@
 /*----- Revision history --------------------------------------------------* 
  *
  * $Log: testrig.c,v $
+ * Revision 1.5  1999/05/21 22:14:30  mdw
+ * Take advantage of the new dynamic string macros.
+ *
  * Revision 1.4  1999/05/19 19:02:17  mdw
  * Aesthetic changes: fix spelling of `initialize'; use uppercase token
  * constants; abandon old double-underscore convention for internal
@@ -111,7 +114,7 @@ static int gettok(FILE *fp)
 
   /* --- Clear the token accumulator --- */
 
-  dstr_reset(&tok);
+  DRESET(&tok);
 
   /* --- Prime the lookahead character --- */
 
@@ -224,7 +227,7 @@ static void cvt_string(const char *s, dstr *d)
 
 static void dump_string(dstr *d, FILE *fp)
 {
-  dstr_write(d, fp);
+  DWRITE(d, fp);
 }
 
 test_type type_string = { cvt_string, dump_string };
@@ -273,7 +276,7 @@ void test_run(int argc, char *argv[],
   ego(argv[0]);
 
   for (i = 0; i < TEST_FIELDMAX; i++)
-    dstr_create(&dv[i]);
+    DCREATE(&dv[i]);
 
   /* --- Parse command line arguments --- */
 
@@ -365,7 +368,7 @@ void test_run(int argc, char *argv[],
       /* --- Otherwise I expect a list of words --- */
 
       for (i = 0; cch->f[i]; i++) {
-       dstr_reset(&dv[i]);
+       DRESET(&dv[i]);
        if (t != TOK_WORD)
          die(1, "expected <word>; found `%s'", decode(t));
        cch->f[i]->cvt(tok.buf, &dv[i]);