*.c: General spring-clean of the coding style.
[anag] / util.c
diff --git a/util.c b/util.c
index 97f498e..223fcf4 100644 (file)
--- a/util.c
+++ b/util.c
@@ -56,12 +56,9 @@ static const char *quis = "<unset>";
 void ego(const char *p)
 {
   const char *q = p;
-  while (*q) {
-    if (*q++ == PATHSEP)
-      p = q;
-  }
-  if (*p == '-')
-    p++;
+  while (*q)
+    if (*q++ == PATHSEP) p = q;
+  if (*p == '-') p++;
   quis = p;
 }
 
@@ -87,20 +84,16 @@ int pquis(FILE *fp, const char *p)
   while (*p) {
     sz = strcspn(p, "$");
     if (sz) {
-      if (fwrite(p, 1, sz, fp) < sz)
-       return (EOF);
+      if (fwrite(p, 1, sz, fp) < sz) return (EOF);
       p += sz;
     }
     if (*p == '$') {
       p++;
       if (*p == '$') {
-       if (fputc('$', fp) == EOF)
-         return (EOF);
+       if (fputc('$', fp) == EOF) return (EOF);
        p++;
-      } else {
-       if (fputs(quis, fp) == EOF)
-         return (EOF);
-      }
+      } else if (fputs(quis, fp) == EOF)
+       return (EOF);
     }
   }
   return (0);
@@ -142,8 +135,7 @@ void die(const char *f, ...)
 void *xmalloc(size_t sz)
 {
   void *p = malloc(sz);
-  if (!p)
-    die("not enough memory");
+  if (!p) die("not enough memory");
   return (p);
 }
 
@@ -161,8 +153,7 @@ void *xmalloc(size_t sz)
 void *xrealloc(void *p, size_t sz)
 {
   p = realloc(p, sz);
-  if (!p)
-    die("not enough memory");
+  if (!p) die("not enough memory");
   return (p);
 }
 
@@ -208,23 +199,15 @@ void dstr_ensure(dstr *d, size_t sz)
   size_t rq = d->len + sz;
   size_t nsz;
 
-  /* --- If we have enough space, just leave it --- */
-
-  if (rq <= d->sz)
-    return;
-
-  /* --- Grow the buffer --- */
+  /* If we have enough space, just leave it. */
+  if (rq <= d->sz) return;
 
+  /* Grow the buffer. */
   nsz = d->sz;
-
-  if (nsz == 0)
-    nsz = (DSTR_INITSZ >> 1);
+  if (nsz == 0) nsz = (DSTR_INITSZ >> 1);
   do nsz <<= 1; while (nsz < rq);
-
-  if (d->buf)
-    d->buf = xrealloc(d->buf, nsz);
-  else
-    d->buf = xmalloc(nsz);
+  if (d->buf) d->buf = xrealloc(d->buf, nsz);
+  else d->buf = xmalloc(nsz);
   d->sz = nsz;
 }
 
@@ -250,33 +233,27 @@ int dstr_putline(dstr *d, FILE *fp)
 
   for (;;) {
 
-    /* --- Read the next byte --- */
-
+    /* Read the next byte. */
     ch = getc(fp);
 
-    /* --- End-of-file when no characters read is special --- */
-
-    if (ch == EOF && !rd)
-      return (EOF);
-
-    /* --- Make sure there's some buffer space --- */
+    /* End-of-file when no characters read is special. */
+    if (ch == EOF && !rd) return (EOF);
 
+    /* Make sure there's some buffer space. */
     if (!left) {
       d->len = off;
       dstr_ensure(d, 1);
       left = d->sz - off;
     }
 
-    /* --- End-of-file or newline ends the loop --- */
-
+    /* End-of-file or newline ends the loop. */
     if (ch == EOF || ch == '\n') {
       d->buf[off] = 0;
       d->len = off;
       return rd;
     }
 
-    /* --- Append the character and continue --- */
-
+    /* Append the character and continue. */
     d->buf[off++] = ch;
     left--; rd++;
   }