]> git.saurik.com Git - apple/file_cmds.git/blobdiff - dd/conv.c
file_cmds-90.tar.gz
[apple/file_cmds.git] / dd / conv.c
index 552e0d91d26c1411d132a2849d6e57d61a2c4006..855a7943de252ae234594ba4d588490bbf1ea1f4 100644 (file)
--- a/dd/conv.c
+++ b/dd/conv.c
@@ -1,5 +1,3 @@
-/*     $NetBSD: conv.c,v 1.8 1998/07/28 05:15:46 mycroft Exp $ */
-
 /*-
  * Copyright (c) 1991, 1993, 1994
  *     The Regents of the University of California.  All rights reserved.
  * SUCH DAMAGE.
  */
 
-#include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)conv.c     8.3 (Berkeley) 4/2/94";
-#else
-__RCSID("$NetBSD: conv.c,v 1.8 1998/07/28 05:15:46 mycroft Exp $");
 #endif
+static const char rcsid[] =
+  "$FreeBSD: src/bin/dd/conv.c,v 1.16 2002/02/02 06:24:12 imp Exp $";
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -61,11 +58,11 @@ __RCSID("$NetBSD: conv.c,v 1.8 1998/07/28 05:15:46 mycroft Exp $");
  * Worst case buffer calculation is (ibs + obs - 1).
  */
 void
-def()
+def(void)
 {
-       int cnt;
        u_char *inp;
        const u_char *t;
+       size_t cnt;
 
        if ((t = ctab) != NULL)
                for (inp = in.dbp - (cnt = in.dbrcnt); cnt--; ++inp)
@@ -90,23 +87,13 @@ def()
 }
 
 void
-def_close()
+def_close(void)
 {
        /* Just update the count, everything is already in the buffer. */
        if (in.dbcnt)
                out.dbcnt = in.dbcnt;
 }
 
-#ifdef NO_CONV
-/* Build a smaller version (i.e. for a miniroot) */
-/* These can not be called, but just in case...  */
-static char no_block[] = "unblock and -DNO_CONV?";
-void block()       { errx(1, no_block + 2); }
-void block_close() { errx(1, no_block + 2); }
-void unblock()       { errx(1, no_block); }
-void unblock_close() { errx(1, no_block); }
-#else  /* NO_CONV */
-
 /*
  * Copy variable length newline terminated records with a max size cbsz
  * bytes to output.  Records less than cbs are padded with spaces.
@@ -115,13 +102,13 @@ void unblock_close() { errx(1, no_block); }
  * max out buffer: obs + cbsz
  */
 void
-block()
+block(void)
 {
-       static int intrunc;
-       int ch = 0;     /* pacify gcc */
-       int cnt, maxlen;
        u_char *inp, *outp;
        const u_char *t;
+       size_t cnt, maxlen;
+       static int intrunc;
+       int ch;
 
        /*
         * Record truncation can cross block boundaries.  If currently in a
@@ -130,8 +117,8 @@ block()
         * left empty.
         */
        if (intrunc) {
-               for (inp = in.db, cnt = in.dbrcnt;
-                   cnt && *inp++ != '\n'; --cnt);
+               for (inp = in.db, cnt = in.dbrcnt; cnt && *inp++ != '\n'; --cnt)
+                       ;
                if (!cnt) {
                        in.dbcnt = 0;
                        in.dbp = in.db;
@@ -147,15 +134,16 @@ block()
         * Copy records (max cbsz size chunks) into the output buffer.  The
         * translation is done as we copy into the output buffer.
         */
+       ch = 0;
        for (inp = in.dbp - in.dbcnt, outp = out.dbp; in.dbcnt;) {
                maxlen = MIN(cbsz, in.dbcnt);
                if ((t = ctab) != NULL)
-                       for (cnt = 0;
-                           cnt < maxlen && (ch = *inp++) != '\n'; ++cnt)
+                       for (cnt = 0; cnt < maxlen && (ch = *inp++) != '\n';
+                           ++cnt)
                                *outp++ = t[ch];
                else
-                       for (cnt = 0;
-                           cnt < maxlen && (ch = *inp++) != '\n'; ++cnt)
+                       for (cnt = 0; cnt < maxlen && (ch = *inp++) != '\n';
+                           ++cnt)
                                *outp++ = ch;
                /*
                 * Check for short record without a newline.  Reassemble the
@@ -200,7 +188,7 @@ block()
 }
 
 void
-block_close()
+block_close(void)
 {
        /*
         * Copy any remaining data into the output buffer and pad to a record.
@@ -213,8 +201,8 @@ block_close()
        if (in.dbcnt) {
                ++st.trunc;
                (void)memmove(out.dbp, in.dbp - in.dbcnt, in.dbcnt);
-               (void)memset(out.dbp + in.dbcnt,
-                   ctab ? ctab[' '] : ' ', cbsz - in.dbcnt);
+               (void)memset(out.dbp + in.dbcnt, ctab ? ctab[' '] : ' ',
+                   cbsz - in.dbcnt);
                out.dbcnt += cbsz;
        }
 }
@@ -227,11 +215,11 @@ block_close()
  * max out buffer: obs + cbsz
  */
 void
-unblock()
+unblock(void)
 {
-       int cnt;
        u_char *inp;
        const u_char *t;
+       size_t cnt;
 
        /* Translation and case conversion. */
        if ((t = ctab) != NULL)
@@ -243,16 +231,16 @@ unblock()
         * spaces.
         */
        for (inp = in.db; in.dbcnt >= cbsz; inp += cbsz, in.dbcnt -= cbsz) {
-               for (t = inp + cbsz - 1; t >= inp && *t == ' '; --t);
+               for (t = inp + cbsz - 1; t >= inp && *t == ' '; --t)
+                       ;
                if (t >= inp) {
                        cnt = t - inp + 1;
                        (void)memmove(out.dbp, inp, cnt);
                        out.dbp += cnt;
                        out.dbcnt += cnt;
                }
-               ++out.dbcnt;
                *out.dbp++ = '\n';
-               if (out.dbcnt >= out.dbsz)
+               if (++out.dbcnt >= out.dbsz)
                        dd_out(0);
        }
        if (in.dbcnt)
@@ -261,14 +249,15 @@ unblock()
 }
 
 void
-unblock_close()
+unblock_close(void)
 {
-       int cnt;
        u_char *t;
+       size_t cnt;
 
        if (in.dbcnt) {
                warnx("%s: short input record", in.name);
-               for (t = in.db + in.dbcnt - 1; t >= in.db && *t == ' '; --t);
+               for (t = in.db + in.dbcnt - 1; t >= in.db && *t == ' '; --t)
+                       ;
                if (t >= in.db) {
                        cnt = t - in.db + 1;
                        (void)memmove(out.dbp, in.db, cnt);
@@ -279,5 +268,3 @@ unblock_close()
                *out.dbp++ = '\n';
        }
 }
-
-#endif /* NO_CONV */