-/* $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>
* 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)
}
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.
* 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
* 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;
* 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
}
void
-block_close()
+block_close(void)
{
/*
* Copy any remaining data into the output buffer and pad to a record.
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;
}
}
* 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)
* 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)
}
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);
*out.dbp++ = '\n';
}
}
-
-#endif /* NO_CONV */