add 1994 copyright
[unix-history] / usr / src / bin / dd / conv.c
index 80efe7e..8de85f1 100644 (file)
@@ -1,6 +1,6 @@
 /*-
 /*-
- * Copyright (c) 1991 The Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1991, 1993, 1994
+ *     The Regents of the University of California.  All rights reserved.
  *
  * This code is derived from software contributed to Berkeley by
  * Keith Muller of the University of California, San Diego and Lance
  *
  * This code is derived from software contributed to Berkeley by
  * Keith Muller of the University of California, San Diego and Lance
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)conv.c     5.4 (Berkeley) %G%";
+static char sccsid[] = "@(#)conv.c     8.3 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/param.h>
 #endif /* not lint */
 
 #include <sys/param.h>
+
+#include <err.h>
 #include <string.h>
 #include <string.h>
+
 #include "dd.h"
 #include "extern.h"
 
 #include "dd.h"
 #include "extern.h"
 
@@ -27,8 +30,8 @@ static char sccsid[] = "@(#)conv.c    5.4 (Berkeley) %G%";
 void
 def()
 {
 void
 def()
 {
-       register int cnt;
-       register u_char *inp, *t;
+       int cnt;
+       u_char *inp, *t;
 
        if (t = ctab)
                for (inp = in.dbp - (cnt = in.dbrcnt); cnt--; ++inp)
 
        if (t = ctab)
                for (inp = in.dbp - (cnt = in.dbrcnt); cnt--; ++inp)
@@ -71,9 +74,8 @@ void
 block()
 {
        static int intrunc;
 block()
 {
        static int intrunc;
-       register int ch, cnt;
-       register u_char *inp, *outp, *t;
-       int maxlen;
+       int ch, cnt, maxlen;
+       u_char *inp, *outp, *t;
 
        /*
         * Record truncation can cross block boundaries.  If currently in a
 
        /*
         * Record truncation can cross block boundaries.  If currently in a
@@ -114,7 +116,7 @@ block()
                 * input block.
                 */
                if (ch != '\n' && in.dbcnt < cbsz) {
                 * input block.
                 */
                if (ch != '\n' && in.dbcnt < cbsz) {
-                       bcopy(in.dbp - in.dbcnt, in.db, in.dbcnt);
+                       memmove(in.db, in.dbp - in.dbcnt, in.dbcnt);
                        break;
                }
 
                        break;
                }
 
@@ -123,11 +125,17 @@ block()
                if (ch == '\n')
                        --in.dbcnt;
 
                if (ch == '\n')
                        --in.dbcnt;
 
-               /* Pad short records with "spaces". */
+               /* Pad short records with spaces. */
                if (cnt < cbsz)
                        (void)memset(outp, ctab ? ctab[' '] : ' ', cbsz - cnt);
                else {
                if (cnt < cbsz)
                        (void)memset(outp, ctab ? ctab[' '] : ' ', cbsz - cnt);
                else {
-                       ++st.trunc;
+                       /*
+                        * If the next character wouldn't have ended the
+                        * block, it's a truncation.
+                        */
+                       if (!in.dbcnt || *inp != '\n')
+                               ++st.trunc;
+
                        /* Toss characters to a newline. */
                        for (; in.dbcnt && *inp++ != '\n'; --in.dbcnt);
                        if (!in.dbcnt)
                        /* Toss characters to a newline. */
                        for (; in.dbcnt && *inp++ != '\n'; --in.dbcnt);
                        if (!in.dbcnt)
@@ -158,7 +166,7 @@ block_close()
         */
        if (in.dbcnt) {
                ++st.trunc;
         */
        if (in.dbcnt) {
                ++st.trunc;
-               bcopy(in.dbp - in.dbcnt, out.dbp, in.dbcnt);
+               memmove(out.dbp, in.dbp - in.dbcnt, in.dbcnt);
                (void)memset(out.dbp + in.dbcnt,
                    ctab ? ctab[' '] : ' ', cbsz - in.dbcnt);
                out.dbcnt += cbsz;
                (void)memset(out.dbp + in.dbcnt,
                    ctab ? ctab[' '] : ' ', cbsz - in.dbcnt);
                out.dbcnt += cbsz;
@@ -175,8 +183,8 @@ block_close()
 void
 unblock()
 {
 void
 unblock()
 {
-       register int cnt;
-       register u_char *inp, *t;
+       int cnt;
+       u_char *inp, *t;
 
        /* Translation and case conversion. */
        if (t = ctab)
 
        /* Translation and case conversion. */
        if (t = ctab)
@@ -191,7 +199,7 @@ unblock()
                for (t = inp + cbsz - 1; t >= inp && *t == ' '; --t);
                if (t >= inp) {
                        cnt = t - inp + 1;
                for (t = inp + cbsz - 1; t >= inp && *t == ' '; --t);
                if (t >= inp) {
                        cnt = t - inp + 1;
-                       bcopy(inp, out.dbp, cnt);
+                       memmove(out.dbp, inp, cnt);
                        out.dbp += cnt;
                        out.dbcnt += cnt;
                }
                        out.dbp += cnt;
                        out.dbcnt += cnt;
                }
@@ -201,22 +209,22 @@ unblock()
                        dd_out(0);
        }
        if (in.dbcnt)
                        dd_out(0);
        }
        if (in.dbcnt)
-               bcopy(in.dbp - in.dbcnt, in.db, in.dbcnt);
+               memmove(in.db, in.dbp - in.dbcnt, in.dbcnt);
        in.dbp = in.db + in.dbcnt;
 }
 
 void
 unblock_close()
 {
        in.dbp = in.db + in.dbcnt;
 }
 
 void
 unblock_close()
 {
-       register int cnt;
-       register u_char *t;
+       int cnt;
+       u_char *t;
 
        if (in.dbcnt) {
 
        if (in.dbcnt) {
-               warn("%s: short input record", in.name);
+               warnx("%s: short input record", in.name);
                for (t = in.db + in.dbcnt - 1; t >= in.db && *t == ' '; --t);
                if (t >= in.db) {
                        cnt = t - in.db + 1;
                for (t = in.db + in.dbcnt - 1; t >= in.db && *t == ' '; --t);
                if (t >= in.db) {
                        cnt = t - in.db + 1;
-                       bcopy(in.db, out.dbp, cnt);
+                       memmove(out.dbp, in.db, cnt);
                        out.dbp += cnt;
                        out.dbcnt += cnt;
                }
                        out.dbp += cnt;
                        out.dbcnt += cnt;
                }